My intent is to take an inbound PDF and split it into multiple outbound tiff files. Seems simple enough.
But I also want each output tiff file to start with the first page of the PDF. Which sounded simple enough.
Snipped of code:
OutputStream imageStream = null;
Document pdfDocument;
Resolution resolution = new Resolution(200);
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.setCompression(CompressionType.CCITT4);
tiffSettings.setDepth(ColorDepth.Format4bpp);
tiffSettings.setSkipBlankPages(true);
TiffDevice tiffDevice;
tiffDevice = new TiffDevice(resolution, tiffSettings);
try {
File inFile= new File(C:/Development/testdata/Brian.pdf");
pdfDocument = new Document(inputFilePath);
imageStream = new FileOutputStream("C:/Development/testdata/Brian_1.tiff");
tiffDevice.process(pdfDocument, 1, 100, imageStream);
imageStream.close();
imageStream = new FileOutputStream("C:/Development/testdata/Brian_2.tiff");
tiffDevice.process(pdfDocument, 1, 1, imageStream);
tiffDevice.process(pdfDocument, 101, 200, imageStream);
imageStream.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
Seems simple enough. And does create two tiff files. The first file is just file, contains 1-100 viewable pages.
However, the second output shows only the first page. Even though the size of the output file is clearly large enough to include “page 1” of the PDF as well as “pages 101 thru 200”.
When I remove the writing of the first PDF page to the second file, the resulting tiff file is viewable as expected.
There is something not quite right about how I am attempting to write a page, and then more pages to the output tiff.
Looking for suggestions that are not “split the PDF into multiple PDF files and then process those”.
The inbound PDF file is 391 pages.
Thanks.