public static final String MIME_TYPE = "image/png";
/** The file syntax prefix, eg. "page" will output "page1.png" etc */
- private String fileSyntax;
+ private String filePrefix;
/** The output directory where images are to be written */
private File outputDir;
// the file provided on the command line
File f = getUserAgent().getOutputFile();
-
- outputDir = f.getParentFile();
-
- // extracting file name syntax
- String s = f.getName();
- int i = s.lastIndexOf(".");
- if (s.charAt(i - 1) == '1') {
- i--; // getting rid of the "1"
+ if (f == null) {
+ //No filename information available. Only the first page will be rendered.
+ outputDir = null;
+ filePrefix = null;
+ } else {
+ outputDir = f.getParentFile();
+
+ // extracting file name syntax
+ String s = f.getName();
+ int i = s.lastIndexOf(".");
+ if (s.charAt(i - 1) == '1') {
+ i--; // getting rid of the "1"
+ }
+ filePrefix = s.substring(0, i);
}
- fileSyntax = s.substring(0, i);
+
}
public void stopRenderer() throws IOException {
for (int i = 0; i < pageViewportList.size(); i++) {
+ OutputStream os = getCurrentOutputStream(i);
+ if (os == null) {
+ getLogger().warn("No filename information available."
+ + " Stopping early after the first page.");
+ break;
+ }
// Do the rendering: get the image for this page
RenderedImage image = (RenderedImage) getPageImage((PageViewport) pageViewportList
.get(i));
// Encode this image
- getLogger().debug("Encoding Page " + (i + 1));
+ getLogger().debug("Encoding page " + (i + 1));
renderParams = PNGEncodeParam.getDefaultEncodeParam(image);
- OutputStream os = getCurrentOutputStream(i);
+
+ // Set resolution
+ float pixSzMM = userAgent.getPixelUnitToMillimeter();
+ // num Pixs in 1 Meter
+ int numPix = (int)((1000 / pixSzMM) + 0.5);
+ renderParams.setPhysicalDimension(numPix, numPix, 1); // 1 means 'pix/meter'
+
+ // Encode PNG image
PNGImageEncoder encoder = new PNGImageEncoder(os, renderParams);
encoder.encode(image);
os.flush();
return firstOutputStream;
}
- File f = new File(outputDir + File.separator + fileSyntax
- + (pageNumber + 1) + ".png");
- try {
- OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
- return os;
- } catch (FileNotFoundException e) {
- new FOPException("Can't build the OutputStream\n" + e);
+ if (filePrefix == null) {
return null;
+ } else {
+ File f = new File(outputDir + File.separator + filePrefix
+ + (pageNumber + 1) + ".png");
+ try {
+ OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
+ return os;
+ } catch (FileNotFoundException e) {
+ new FOPException("Can't build the OutputStream\n" + e);
+ return null;
+ }
}
}
}