Aspose.PDF for .NET is not exporting to PNG invisible PDF layers

I’m evaluating the Aspose.PDF for .NET and one feature I need is to be able to control which layer will be exported but I’m afraid this tool is not prepared for that.

  1. I open a multi-layer PDF in Adobe Acrobat and only few layers are visible but I can change and visualize them there;
  2. I’m opening this PDF file using the Aspose API and there is not any layer in the page, just returning null;
  3. I export to PNG (using pngDevice.Process) and just get an image with those few visible layers.

I found few old issues tickets related to this layers problem and would like to know if it’s still a problem or if there is other way to work with layers using this API.

@diego.couto,

Thanks for contacting support.

Can you please share source files to further investigate this issue along with working sample project so that we may help you out.

Thanks for replying.

It’s just a simple code that was supposed to show layers to be selected if there is any or convert directly if there isn’t but it always getting no layers as I’ve commented on the case.

[HttpPost]
public ActionResult ExportPdfFile(HttpPostedFileBase fileUpload)
{
if (fileUpload != null && fileUpload.ContentLength > 0)
{
var model = new Models.ExportPdfFile();
Document document = new Document(fileUpload.InputStream);

            if (document.Pages != null && document.Pages.Count > 0)
            {
                string newFileNamePng = $"{Path.GetFileNameWithoutExtension(fileUpload.FileName)}.png";

                if (document.Pages[1].Layers != null && document.Pages[1].Layers.Count > 0)
                {
                    Dictionary<string, string> layers = new Dictionary<string, string>();

                    model.Layers = document.Pages[1].Layers.ToDictionary(x => x.Id, y => y.Name);
                }
                else
                {
                    model.FilesExported.Add(newFileNamePng, ExportToPNG(document.Pages[1], newFileNamePng));
                }
            }

            return View(model);
        }
        else
            return View("Index");
    }        

    public string ExportToPNG(Page page, string outputName)
    {
        string fileName = Path.Combine(GetCurrentFolder(), outputName);

        using (FileStream imageStream = new FileStream(fileName, FileMode.Create))
        {
            // Create PNG device with specified attributes
            // Width, Height, Resolution, Quality
            // Quality [0-100], 100 is Maximum
            // Create Resolution object
            Resolution resolution = new Resolution(300);
            PngDevice pngDevice = new PngDevice(resolution);

            // Convert a particular page and save the image to stream
            pngDevice.Process(page, imageStream);

            // Close stream
            imageStream.Close();
        }

        return $"/{PngFolder}/{outputName}";
    }

@diego.couto,

Can you please share source PDF file with us to further investigate this issue in more details.

LayeredPDF.pdf (2.2 MB)

Follow the PDF file. Thanks

@diego.couto,

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-47995 in our issue tracking system to investigate and resolve this issue as soon possible.