Hello,
I'm validating the use of pdfbox 1.8.6 for the creation of a pdf file for an
editor. Therefore I need the possibility to include a pdf file (picture).
I tried some coding, but it is not fully readable with Acrobat Reader. I'm not
sure, if I use the wrong concept for this or if it is simple a mistake in
pdfbox.
Please can you give me a hint.
My coding:
public static void main(String[] args) {
try
{
float width = 150.0f;
float height = 400.0f;
PDRectangle sizePDF = new PDRectangle(width,height);
PDDocument aDoc = new PDDocument();
PDPage aPage = new PDPage(sizePDF);
aDoc.addPage( aPage );
PDPageContentStream aContent = new PDPageContentStream(aDoc, aPage);
PDFont font = PDType1Font.HELVETICA_BOLD;
aContent.beginText();
aContent.setFont( font, 12 );
aContent.moveTextPositionByAmount( 2, 5 );
aContent.drawString( "Import a pdf file:" );
aContent.endText();
File aFile = new File("c:\\hallo.pdf");
byte buffer[] = new byte[(int) aFile.length()];
FileInputStream In = new FileInputStream(aFile);
In.read(buffer);
In.close();
ByteArrayInputStream in = new ByteArrayInputStream(buffer);
PDStream aStream = new PDStream (aDoc, in);
PDXObjectForm aObject = new PDXObjectForm( aStream );
aContent.drawXObject(aObject,2,30,150,150);
aContent.close();
aDoc.save( "c:\\pdftest.pdf");
aDoc.close();
}
catch (Exception e)
{
System.out.println(" error creating pdf file."
+ e.toString());
}
}
}
The used data and the output is attached to the mail.
Thanks
Klaus Graaf