1

Flattening a PDF means multiple layers of the content will be merged into a single layer. However, the results vary from one service to another as what each service sees in the layers differs.

Basically, by flattening a PDF the image of the page of a PDF content is taken and replaced on that same page. This means the texts in that PDF will no longer be editable as they will become an image. Similarly, if there are any annotations, etc., they will become an image and no longer be editable or selectable.

https://www.sejda.com/flatten-pdf does this job by using the human interface. What is required is an API similar to this functionality so that applications can flatten the PDFs. Checked and confirmed with Sejda that they do not offer any API services even if it is on a paid basis.

Requesting anyone to share who knows any API service or .Net library that can flatten a PDF.

2 Answers 2

3

There seems to be some confusion between the options "flatten" and "rasterize" in PDF files.

When you rasterize a PDF, you convert it into an image with a specific resolution DPI. This means that all text and objects in the PDF are turned into images, and any vector-based features are lost.

On the other hand, flattening a PDF typically involves merging or combining its layers into one. However, this process does not(should not) convert objects into images. Instead, it keeps them in a vector format, which prevents copying of forms and text. Any text in the PDF is converted into vectors to preserve its formatting and quality.

You can test both methods using online REST API:

Rasterize https://www.convertapi.com/pdf-to-rasterize

Flatten https://www.convertapi.com/pdf-to-flatten

2

The company I work for has the LEADTOOLS PDF library which simplifies doing this using .NET classes (and other platforms if needed).

Here's the needed C# code to convert any type of PDF to flat-image PDF that doesn't contain searchable text:

RasterCodecs codecs = new RasterCodecs();
//specify the desired loading DPI. Increase it to improve quality
codecs.Options.RasterizeDocument.Load.XResolution = 200;
codecs.Options.RasterizeDocument.Load.YResolution = 200;
//load all pages
RasterImage pdfPages = codecs.Load(inputPdfName, 24, CodecsLoadByteOrder.Bgr, 1, -1);
//save all pages
codecs.Save(pdfPages, flatPdfName, RasterImageFormat.RasPdfJpeg411, 24, 1, -1, 1, CodecsSavePageMode.Overwrite);

The code shows one of the useful options, which is selecting the DPI resolution used when converting the pages to images. The library offers many other features that allow optimizing or customizing the conversion process.

If you would like to try the SDK, there's a free evaluation here. The evaluation comes with full documentations, sample projects and free technical support through email and chat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.