How to add .png images to pdf using Apache PDFBox

前端 未结 1 816
甜味超标
甜味超标 2021-02-20 01:42

When I try to draw png images using pdfBox, the pages remain blank. Is there any way to insert png images using pdfBox?

public void createPDFFromImage( String in         


        
相关标签:
1条回答
  • 2021-02-20 02:01

    There is a pretty nice utility class PDImageXObject to load Images from a java.io.File. As far as I know, it works well with jpg and png files.

    PDImageXObject pdImage = PDImageXObject.createFromFileByContent(imageFile, doc);
    contentStream.drawImage(pdImage, 20f, 20f); 
    
    0 讨论(0)
提交回复
热议问题