/** * Simple PDF glyph dumper based on PDFlib TET * * Required software: TET 5.2 (if you define the constants TET.CT_SEQ_START * etc. the code can also be used with TET 5.0) *
* Required data: PDF document
*
*/
package com.pdflib.cookbook.tet.text;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Formatter;
import java.util.Locale;
import com.pdflib.TET;
import com.pdflib.TETException;
public class glyphinfo {
/**
* Global option list
*/
static final String globaloptlist = "searchpath={{../input} {../resource/cmap}}";
/**
* Document-specific option list
*/
static final String docoptlist = "";
/**
* Page-specific option list
*/
static final String pageoptlist = "granularity=word";
private static void print_color_value(Formatter formatter, TET tet, int doc, int colorid) throws TETException {
String csname; /* color space name */
int i;
/*
* We handle only the fill color, but ignore the stroke color. The stroke color
* can be retrieved analogously with the keyword "stroke".
*/
tet.get_color_info(doc, colorid, "usage=fill");
if (tet.colorspaceid == -1 && tet.patternid == -1) {
formatter.format(" (not filled)");
return;
}
formatter.format(" (");
if (tet.patternid != -1) {
int patterntype = (int) tet.pcos_get_number(doc, "patterns[" + tet.patternid + "]/PatternType");
if (patterntype == 1) /* Tiling pattern */
{
int painttype = (int) tet.pcos_get_number(doc, "patterns[" + tet.patternid + "]/PaintType");
if (painttype == 1) {
formatter.format("colored Pattern)");
return;
} else if (painttype == 2) {
formatter.format("uncolored Pattern, base color: ");
/* FALLTHROUGH to colorspaceid output */
}
} else if (patterntype == 2) /* Shading pattern */
{
int shadingtype = (int) tet.pcos_get_number(doc, "patterns[" + tet.patternid + "]/Shading/ShadingType");
formatter.format("shading Pattern, ShadingType=%d)", shadingtype);
return;
}
}
csname = tet.pcos_get_string(doc, "colorspaces[" + tet.colorspaceid + "]/name");
formatter.format("%s", csname);
/* Emit more details depending on the colorspace type */
if (csname.equals("ICCBased")) {
int iccprofileid;
String profilename;
String profilecs;
String errormessage;
iccprofileid = (int) tet.pcos_get_number(doc, "colorspaces[" + tet.colorspaceid + "]/iccprofileid");
errormessage = tet.pcos_get_string(doc, "iccprofiles[" + iccprofileid + "]/errormessage");
/* Check whether the embedded profile is damaged */
if (errormessage.equals("")) {
formatter.format(" (%s)", errormessage);
} else {
profilename = tet.pcos_get_string(doc, "iccprofiles[" + iccprofileid + "]/profilename");
formatter.format(" '%s'", profilename);
profilecs = tet.pcos_get_string(doc, "iccprofiles[" + iccprofileid + "]/profilecs");
formatter.format(" '%s'", profilecs);
}
} else if (csname.equals("Separation")) {
String colorantname = tet.pcos_get_string(doc, "colorspaces[" + tet.colorspaceid + "]/colorantname");
formatter.format(" '%s'", colorantname);
} else if (csname.equals("DeviceN")) {
formatter.format(" ");
for (i = 0; i < tet.components.length; i++) {
String colorantname = tet.pcos_get_string(doc,
"colorspaces[" + tet.colorspaceid + "]/colorantnames[" + i + "]");
formatter.format("%s", colorantname);
if (i != tet.components.length - 1)
formatter.format("/");
}
} else if (csname.equals("Indexed")) {
int baseid = (int) tet.pcos_get_number(doc, "colorspaces[" + tet.colorspaceid + "]/baseid");
csname = tet.pcos_get_string(doc, "colorspaces[" + baseid + "]/name");
formatter.format(" %s", csname);
}
formatter.format(" ");
for (i = 0; i < tet.components.length; i++) {
formatter.format("%g", tet.components[i]);
if (i != tet.components.length - 1)
formatter.format("/");
}
formatter.format(")");
}
public static void main(String argv[]) {
TET tet = null;
try {
if (argv.length != 1) {
throw new Exception("usage: glyphinfo