Can't add an image to a pdf using PDFBox

后端 未结 3 1582
再見小時候
再見小時候 2020-12-10 10:45

I\'m writing a java app that creates a pdf from scratch using the pdfbox library.
I need to place a jpg image in one of the page.

I\'m using this code:



        
3条回答
  •  孤城傲影
    2020-12-10 10:55

    this is how default constructor for PDPageContentStream looks like:

    public PDPageContentStream(PDDocument document, PDPage sourcePage) throws IOException
    {
        this(document, sourcePage, AppendMode.OVERWRITE, true, false);
    }
    

    Problem is AppendMode.OVERWRITE for me using another constructor with parameter PDPageContentStream.AppendMode.APPEND resolved a problem

    For me this worked:

    PDPageContentStream contentStream =
            new PDPageContentStream(document, page, PDPageContentStream.AppendMode.APPEND, true, false);
    

提交回复
热议问题