Hello,
I am trying to embed an image in a PDF.
How do you load an image in PDFBox?
PDDocument.load() does not work ("Error: Header doesn't contain versioninfo")
because my JPG image is not a PDF.
Any suggestions?
Many thanks.
Philippe
void embedFile(PDPage aPage) throws URISyntaxException, IOException {
final String rond = "/META-INF/templates/rond.jpg";
final java.net.URL rondUrl = getClass().getClass().getResource(rond);
final File rondPath = new File(rondUrl.toURI());
final String randomPdfName = "random.pdf";
// Error in original code: randomPdfName missing
final File randomAccessFilePath = new File(pathToRandomAccessDirectory,
randomPdfName);
RandomAccess randomAccessFile = new RandomAccessFile(randomAccessFilePath,
"rw");
PDDocument importedRond = PDDocument.load(rondPath);
PDEmbeddedFile embFile = new PDEmbeddedFile(importedRond);
List<PDAnnotation> annotationList = aPage.getAnnotations();
BoundingBox box = new BoundingBox(10, 790, 80, 740);
PDRectangle rect = new PDRectangle(box);
PDAnnotationFileAttachment attach = new PDAnnotationFileAttachment();
attach.setRectangle(rect);
PDFileSpecification simpleSpec = new PDSimpleFileSpecification();
simpleSpec.setFile("image");
attach.setFile(simpleSpec);
attach.setPage(aPage);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]