> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/xamarin/optimization/flatten.md).

# Flatten a PDF in Xamarin

Learn how to flatten a PDF using default settings, compress & optimize PDF files with 'pdftron.PDF.Flattener'. Speed up PDF rendering on mobile devices and the Web by simplifying page content while ma

{% hint style="warning" %}
For Android, available in the full version of the library only. See [Apryse full or standard?](/xamarin/get-started/faq/full-vs-standard.md)
{% endhint %}

To flatten a PDF using default settings.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
PDFDoc doc = new PDFDoc(filename);
Flattener fl = new Flattener();
fl.Process(doc, Flattener.FlattenMode.e_fast);
```

{% endcode %}
{% endtab %}
{% endtabs %}

[Compress & optimize PDF files](/xamarin/get-started/samples.md#optimizer) Full code sample which shows how to use 'pdftron.PDF.Flattener' by simplifying page content (e.g. flattening complex graphics into images) while maintaining vector text.

## About PDF flattener (or mobile PDF optimizer)

PDF Flattener component (pdftron.PDF.Flattener) can be used to speed-up PDF rendering on mobile devices and on the Web.

PDF documents can frequently contain very complex page description (e.g. thousands of paths, different shadings, color spaces, blend modes, large images etc.) that may not be suitable for interactive viewing on mobile devices.

Flattener can be used to speed-up PDF rendering on mobile devices and on the Web by simplifying page content (e.g. flattening complex graphics into images) while maintaining vector text whenever possible.

Flattener can also be used to simplify process of writing custom converters from PDF to other formats. In this case, Flattener can be used as first step in the conversion pipeline to reduce any PDF to a very simple representation (e.g. vector text on top of a background image).

A quick way to try Flattener is by using [DocPub CLI](/cli/docpub/docpub.md) (e.g. docpub -f pdf my.pdf).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/xamarin/optimization/flatten.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
