小编use*_*729的帖子

如何使用Apache PDFBox将.png图像添加到pdf

当我尝试使用pdfBox绘制png图像时,页面保持空白.有没有办法用pdfBox插入png图像?

public void createPDFFromImage( String inputFile, String image, String outputFile ) 
        throws IOException, COSVisitorException
{
    // the document
    PDDocument doc = null;
    try
    {
        doc = PDDocument.load( inputFile );

        //we will add the image to the first page.
        PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get( 0 );

        PDXObjectImage ximage = null;
        if( image.toLowerCase().endsWith( ".jpg" ) )
        {
            ximage = new PDJpeg(doc, new FileInputStream( image ) );
        }
        else if (image.toLowerCase().endsWith(".tif") || image.toLowerCase().endsWith(".tiff"))
        {
            ximage = new PDCcitt(doc, new RandomAccessFile(new File(image),"r"));
        }
        else
        { …
Run Code Online (Sandbox Code Playgroud)

java pdfbox

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

pdfbox ×1