
org.openpdf.renderer.PDFDebugger Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openpdf-renderer Show documentation
Show all versions of openpdf-renderer Show documentation
PDF renderer implementation supporting the subset of PDF 1.4 specification.
The newest version!
package org.openpdf.renderer;
import java.awt.Rectangle;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
public class PDFDebugger {
public final static String DEBUG_DCTDECODE_DATA = "debugdctdecode";
public static final boolean DEBUG_TEXT = false;
public static final boolean DEBUG_IMAGES = false;
public static final boolean DEBUG_OPERATORS = false;
public static final boolean DEBUG_PATH = false;
public static final int DEBUG_STOP_AT_INDEX = 0;
public static final boolean DISABLE_TEXT = false;
public static final boolean DISABLE_IMAGES = false;
public static final boolean DISABLE_PATH_STROKE = false;
public static final boolean DISABLE_PATH_FILL = false;
public static final boolean DISABLE_PATH_STROKE_FILL = false;
public static final boolean DISABLE_CLIP = false;
public static final boolean DISABLE_FORMS = false;
public static final boolean DISABLE_SHADER = false;
public static final boolean SHOW_TEXT_REGIONS = false;
public static final boolean SHOW_TEXT_ANCHOR = false;
public static final boolean DISABLE_THUMBNAILS = false;
public static final long DRAW_DELAY = 0;
public static int debuglevel = 4000;
@SuppressWarnings("serial")
public static class DebugStopException extends Exception {
// nothing to do
}
public static void debugImage(BufferedImage image, String name) {
if (PDFDebugger.DEBUG_IMAGES) {
if(image == null) {
return;
}
try {
// retrieve image
File outputfile = new File("D:/tmp/PDFimages/" + name + ".png");
ImageIO.write(image, "png", outputfile);
} catch (IOException e) {
BaseWatchable.getErrorHandler().publishException(e);
}
}
}
// TODO: add debug level and print it?
public static void debug(String msg, int level) {
if (level > debuglevel) {
System.out.println(escape(msg));
}
}
// TODO: add debug level and print it?
public static void debug(String msg) {
debug(msg, debuglevel);
}
public static String escape(String msg) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < msg.length(); i++) {
char c = msg.charAt(i);
if (c != '\n' && (c < 32 || c >= 127)) {
c = '?';
}
sb.append(c);
}
return sb.toString();
}
public static void setDebugLevel(int level) {
debuglevel = level;
}
public static String dumpStream(byte[] stream) {
return PDFDebugger.escape(new String(stream).replace('\r', '\n'));
}
public static void logPath(GeneralPath path, String operation) {
if (PDFDebugger.DEBUG_PATH){
if (operation != null) {
System.out.println("Operation: " + operation + "; ");
}
System.out.println("Current path: ");
Rectangle b = path.getBounds();
if (b != null)
System.out.println(" Bounds [x=" + b.x + ",y=" + b.y + ",width=" + b.width + ",height=" + b.height + "]");
Point2D p = path.getCurrentPoint();
if (p != null)
System.out.println(" Point [x=" + p.getX() + ",y=" + p.getY() + "]");
}
}
public static void dump(PDFObject obj) throws IOException {
PDFDebugger.debug("dumping PDF object: " + obj);
if (obj == null) {
return;
}
HashMap dict = obj.getDictionary();
PDFDebugger.debug(" dict = " + dict);
for (Object key : dict.keySet()) {
PDFDebugger.debug("key = " + key + " value = " + dict.get(key));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy