.netpdfpngimage-conversionpdf-conversion

How to convert multilayered PDF to PNG choosing which layers will be exported in .NET


I need to be able to convert a multilayered PDF to PNG but I need to be able to set which layer will be exported.

PDF file contains many layers and most of them are not visible. There are APIs that export only layers that are visible and other all. Some APIs let me change the layer visibility but not all that allow that obey this in the conversion.

I have already tried many .Net APIs and few of them allow me to do it but always with some issue. I have already opened few tickets in the related companies but have no clue if and when they will fixed it.

I keep looking for some API that could do this job done and I would appreciate any help.

Follow the APIs and tools I have already tested:

FreeSpire.PDF: did almost the job but the image is being converted with a large empty transparency area around main image (I could not fix that yet).

Syncfusion.Pdf: This seemed to be a good option as well, I can get Layers, set visibility of them but when I export is being exported all layers (visible and invisible). The image quality is very good as well and there is no empty area around.

Dynamic.PDF: seemed another good one but in fact has few resources and not be able to get and work with layers and exporting just invisible ones.

Apitron PDF Rasterizer: Simple to use but it is not possible to access layers and export non visible ones.

Pdf2Png: just have a method to convert and is exporting visible and not visible layers but file result quality is bad. I have tried to change few properties but Quality still bad. It uses Ghostscript behind.

https://ezgif.com/ does not convert invisible layers.

https://pdf.io/pt/pdf2png/ does not convert invisible layers.

https://www.pdfpro.co/files does not convert invisible layers.

https://image.online-convert.com/ does not convert invisible layers.

https://www.zamzar.com/convert/png-to-pdf/ does not convert invisible layers.

https://easypdf.com/pt/pdf-em-png convert invisible layers.

https://cloudconvert.com/pdf-to-png does not convert invisible layers.


Solution

  • The commercial SDK made by the company I work for will do this. You can mix and match the layers anyway you like, when exporting to PNG.

    This sample (go to where the PDFDraw class is used) shows drawing each layer into its own PNG.

    https://www.pdftron.com/documentation/samples/dotnetcore/cs/PDFLayersTest

    From the above code you can see how to mix and match, though if you need more specifics, then please elaborate (sample PDF would also help) on exactly what layers you want to export and I can provide that code.

    To try the sample out, and modify if needed, you can download SDK here: https://www.pdftron.com/documentation/windows/download/windows/

    There is both Windows .NET Framework SDK, and .NET Core SDK for Windows, macOS and Linux, which you can download from link above. Look for the Layers sample in the SDK download.

    Below is an online demo, where you can see interactively switching layers. You can open any PDF. It is the same engine as the server side SDK.

    https://www.pdftron.com/webviewer/demo/pdf-layers