in src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java [90:140]
private ImageInfo loadPDF(String uri, Source src, ImageContext context) throws IOException,
ImageException {
int selectedPage = ImageUtil.needPageIndexFromURI(uri);
URI docURI = deriveDocumentURI(src.getSystemId());
PDDocument pddoc = getDocument(context, docURI, src);
pddoc = Interceptors.getInstance().interceptOnLoad(pddoc, docURI);
//Disable the warning about a missing close since we rely on the GC to decide when
//the cached PDF shall be disposed off.
pddoc.getDocument().setWarnMissingClose(false);
int pageCount = pddoc.getNumberOfPages();
if (selectedPage < 0 || selectedPage >= pageCount) {
throw new ImageException("Selected page (index: " + selectedPage
+ ") does not exist in the PDF file. The document has "
+ pddoc.getNumberOfPages() + " pages.");
}
PDPage page = pddoc.getPage(selectedPage);
PDRectangle mediaBox = page.getMediaBox();
PDRectangle cropBox = page.getCropBox();
PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
int w = Math.round(viewBox.getWidth() * 1000);
int h = Math.round(viewBox.getHeight() * 1000);
//Handle the /Rotation entry on the page dict
int rotation = PDFUtil.getNormalizedRotation(page);
if (rotation == 90 || rotation == 270) {
//Swap width and height
int exch = w;
w = h;
h = exch;
}
ImageSize size = new ImageSize();
size.setSizeInMillipoints(w, h);
size.setResolution(context.getSourceResolution());
size.calcPixelsFromSize();
ImageInfo info = new ImageInfo(uri, ImagePDF.MIME_PDF);
info.setSize(size);
info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, new ImagePDF(info, pddoc));
int lastPageIndex = pddoc.getNumberOfPages() - 1;
if (selectedPage < lastPageIndex) {
info.getCustomObjects().put(ImageInfo.HAS_MORE_IMAGES, Boolean.TRUE);
}
return info;
}