pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@free.fr
Subject Re: Embedding an image
Date Tue, 12 May 2015 15:38:29 GMT
AS a file that is shown on a page.

----- Mail original -----
De: "Tilman Hausherr" <THausherr@t-online.de>
À: users@pdfbox.apache.org
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 phiroc@free.fr:
> 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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message