Flatten a layered PDF

I see that the FlattenAllFields method can be used to flatten all the fields of a PDF. However, is there any way to flatten a layered PDF?

Hi Paul,


Thanks for contacting support.

When form fields are flattened, data cannot be added inside these fields using PDF viewer. From your above requirement of flattening Layered PDF file, do you mean to apply some restrictions so that PDF contents cannot be copied/modified etc. Please share some further details so we may answer accordingly.

Hi Paul,


Thanks for your inquiry. I’m afraid currently Aspose.Pdf for .NET doesn’t support merging multiple layers into a single layer. Can you please share a sample layered document here? So we will investigate it and provide more information.

Moreover, If there is any difference in my understanding and your requirement then please share some more details about your requirements.

Best Regards,

Sample files are attached. Thanks!

Hi Paul,


Thanks for sharing the resource files.

I am afraid the requested feature is
currently not supported but for the sake of implementation, I have logged this
requirement in our issue tracking system under New Features list as PDFNEWNET-35955.
We will further investigate this requirement in details and will keep you
updated on the status of a correction. <o:p></o:p>

We apologize for your inconvenience.

The following post discusses an issue where layers were flattened upon concatening PDF files:

https://forum.aspose.com/t/94054

I'm wondering if we could use this issue as a workaround to meet our requirement of flattening PDFs. We could have a static PDF that we concatenate to any PDF that needs flattening, and then split the PDFs so the result is only the unflattened original PDF.

I see that the issue was resolved in Aspose.Pdf for .NET 7.7.0, so I'm assuming this workaround will not work (we are running 7.7). Can you confirm, and think if there is anything similar we could do that would result in flattening?

Hi Paul,


The issue "Losing layers on PDF files when concatenating logged earlier as PDFNEWNET-34046 (as specified over this forum thread) is resolved. In fact, one of the customers faced an issue where layers of PDF file were removed when PDF files were concatenated. However it got fixed in Aspose.Pdf for .NET 7.7.0 and during my testing with latest release 8.5.0, the layers still persist.

You may consider using product version prior to 7.7.0.

Has this feature (combining multiple layers of a PDF into one layer) been implemented yet? Thanks.

@jamiekitson

The issue discussed and linked here was resolved and it was about deletion of the Layers during PDF conversion. Are you also converting the PDF into PDF/A or only flattening the PDF?

@asad.ali No if you read the whole thread you’ll see it’s about merging layers (PDFNEWNET-35955), the deletion of layers was introduced later. I am trying to combine/merge all layers in a PDF into one in the hope that the PDF will load more quickly. Thanks

@jamiekitson

The issue was about flattening the layers which ultimately remove them and merge all the content into single layer in the resultant PDF. Therefore, you can say that layers can now be merged/combined by flattening the PDF document.

@asad.ali Right, so my question is, has this feature been implemented?

@jamiekitson

Sadly, no specific method or property was added in the API to flatten or merge the PDF Layers. However, if you want to achieve it, you can convert your PDF into PDF/A format which will merge all the present layers into single one