You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by Jochen Schreiber <jo...@googlemail.com> on 2011/01/09 20:09:23 UTC
PDXObjectImage
Hello to everyone,
i want to add jpgs to an PDDocument. This is my code:
PDDocument doc = new PDDocument;
PDPage page = new PDPage();
doc.addPage( page );
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
PDXObjectImage ximage = null;
if( path.toLowerCase().endsWith( ".jpg" ) )
{
ximage = new PDJpeg(doc, new FileInputStream( "projects" + File.separator + mainwin.getCurrentProject().getDirName() + File.separator + path ) );
}
contentStream.drawImage( ximage, 100, 700);
contentStream.close();
doc.close();
The page who will be added to the Document is empty. The file on the system exists and with the file is ok. Where is my fault?
Best Regards,
Jochen Schreiber
Re: PDXObjectImage
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 09.01.2011 20:09, schrieb Jochen Schreiber:
> Hello to everyone,
>
> i want to add jpgs to an PDDocument. This is my code:
>
> PDDocument doc = new PDDocument;
> PDPage page = new PDPage();
> doc.addPage( page );
> PDPageContentStream contentStream = new PDPageContentStream(doc, page);
> PDXObjectImage ximage = null;
>
> if( path.toLowerCase().endsWith( ".jpg" ) )
> {
> ximage = new PDJpeg(doc, new FileInputStream( "projects" + File.separator + mainwin.getCurrentProject().getDirName() + File.separator + path ) );
> }
> contentStream.drawImage( ximage, 100, 700);
> contentStream.close();
> doc.close();
>
> The page who will be added to the Document is empty. The file on the system exists and with the file is ok. Where is my fault?
Just change the order of your steps. The PDJpeg instance has to be created
before opening a PDPageContentStream. The doc.save() is also missing, but I
guess you just forgot to post it, didn't you?
BR
Andreas Lehmkühler