Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Apr 04, 2022 12:19 pm

Hello,
I am trying to add PNG as a new layer to PDF.
When I checked the created PDF,
the image quality seems to be degraded.
Is there a problem with the code?
Or is it another problem?

Thank you

PNG and PDF files:
I attached sample files.

pom.xml:
Code: Select all
<dependency>
    <groupId>e-iceblue</groupId>
    <artifactId>spire.pdf</artifactId>
    <version>5.1.0</version>
</dependency>


code:
Code: Select all
String srcPng = ...;
String srcPdf = ...;
String dstPdf = ...;

PdfDocument srcDocument = null;
try {
    srcDocument = new PdfDocument(srcPdf);
    PdfLayer pdfLayer = srcDocument.getLayers().addLayer("add001");
    PdfCanvas canvas = pdfLayer.createGraphics(srcDocument.getPages().get(0).getCanvas());

    PdfImage pngImage = PdfImage.fromImage(srcPng);
    canvas.drawImage(pngImage, new Point2D.Float(0, 0));

    srcDocument.saveToFile(dstPdf, FileFormat.PDF);

} catch (Exception e) {
    throw new RuntimeException(e);
} finally {
    if (srcDocument != null) {
        srcDocument.close();
    }
}

team_ssb
 
Posts: 24
Joined: Fri Nov 26, 2021 1:30 pm

Tue Apr 05, 2022 6:34 am

Hello,

Thanks for your inquiry.

I have tested your pdf and png and reproduced the issue. I have reported it to our Dev team to investigate if optimization is possible. The ticket is SPIREPDF-5038. I will notify you in time when there is any update.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Tue Apr 05, 2022 10:47 am

Hello,
Thank you for your reply.
Because of the following issue, I am converting SVG to PNG and add PNG to PDF.
If the following issue is resolved, this problem will be given less priority.

Styles in SVG seem to be ignored when converting SVG to PDF
https://www.e-iceblue.com/forum/styles-in-svg-seem-to-be-ignored-when-converting-svg-to-pdf-t11056.html

Thank you

team_ssb
 
Posts: 24
Joined: Fri Nov 26, 2021 1:30 pm

Wed Apr 06, 2022 10:28 am

Hello,

Okey. I will keep you informed as soon as there is any important update.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF