AS a file that is shown on a page. ----- Mail original ----- De: "Tilman Hausherr" <[email protected]> À: [email protected] Envoyé: Mardi 12 Mai 2015 17:34:40 Objet: Re: Embedding an image
With embedding, do you mean as a file attachment or as an image that is shown in a page? Tilman Am 12.05.2015 um 15:32 schrieb [email protected]: > 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] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

