私は、pdfbox ライブラリを使用して最初から pdf を作成する Java アプリを作成しています。
ページの1つにjpg画像を配置する必要があります。
私はこのコードを使用しています:
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
/* ... */
/* code to add some text to the page */
/* ... */
InputStream in = new FileInputStream(new File("c:/myimg.jpg"));
PDJpeg img = new PDJpeg(document, in);
contentStream.drawImage(img, 100, 700);
contentStream.close();
document.save("c:/mydoc.pdf");
コードを実行すると正常に終了しますが、生成された PDF ファイルを Acrobat Reader で開くと、ページが真っ白で画像が配置されません。
代わりに、テキストがページに正しく配置されます。
私の画像をpdfに入れる方法に関するヒントはありますか?