Convert to PDF with advanced options

GroupDocs.Conversion provides the PdfConvertOptions class to give you control over conversion results. Along with common convert options you can specify the following additional options via the PdfConvertOptions class:

  • Format sets the desired file type the input document should be converted to.
  • Width sets the desired image width after conversion.
  • Height sets the desired image height after conversion.
  • Dpi sets the desired page DPI after conversion
  • Password when specified, the resulting document will be protected with the specified password.
  • MarginTop sets the desired page top margin after conversion.
  • MarginBottom sets the desired page bottom margin after conversion.
  • MarginLeft sets the desired page left margin after conversion.
  • MarginRight sets the desired page right margin after conversion.
  • PdfOptions defines the PDF-specific convert options. See below.
  • Rotate sets the page rotation angle. Available options are: None, On90, On180, On270.

The following code snippet shows how to convert to PDF with advanced options:

using (Converter converter = new Converter("sample.docx"))
{
    PdfConvertOptions options = new PdfConvertOptions
    {
        PageNumber = 2,
        PagesCount = 1,
        Rotate = Rotation.On180,
        Dpi = 300,
        Width = 1024,
        Height = 768
    };
    converter.Convert("converted.pdf", options);
}

PdfOptions

The PdfOptions class provides specific options when converting documents to different versions of PDF format.

  • PdfFormat  sets the specific PDF format of the converted document. Available options are: Default, PdfA_1A, PdfA_1B, PdfA_2A, PdfA_3A, PdfA2B, PdfA_2U, PdfA_3B, PdfA_3U, v1_3, v1_4, v1_5, v1_6, v1_7, PdfX_1A, PdfX_3.
  • RemovePdfACompliance whether to remove the Pdf-A compliance.
  • Zoom specifies the zoom level in percentage.
  • Linearize whether to linearize the document for the Web.
  • Grayscale whether to convert the document to grayscale.
  • OptimizationOptions defines the PDF optimization options. See below.
  • FormattingOptions defines the PDF formatting options. See below.

The following code snippet shows how to specify options via the PdfOptions class:

using (Converter converter = new Converter("sample.docx"))
{

    PdfConvertOptions options = new PdfConvertOptions
    {        
        PdfOptions = new PdfOptions
        {
            Grayscale = true,
            Zoom = 200
        }
    };
    converter.Convert("converted.pdf", options);
}

PdfOptimizationOptions

The PdfOptimizationOptions class specifies options for adjusting the PDF conversion process and improving its speed.

  • LinkDuplicateStreams whether to link duplicate streams.
  • RemoveUnusedObjects whether to remove unused objects.
  • RemoveUnusedStreams whether to remove unused streams.
  • CompressImages whether to re-compress all the images in the document. The amount of compression is defined by the ImageQuality property.
  • ImageQuality defines the quality (in percentage) of image compression. Effective when the CompressImages property is set to true. To keep the original quality and image size set this property to 100. To decrease the image size set this property to less than 100.
  • UnembedFonts whether to replace the embedded fonts with references to these fonts. Decreases the file size, but may change the original design of the document.

The following code snippet shows how to specify PDF optimization options:

using (Converter converter = new Converter("sample.docx"))
{

    PdfConvertOptions options = new PdfConvertOptions
    {        
        PdfOptions = new PdfOptions
        {
            OptimizationOptions = new PdfOptimizationOptions
            { 
                CompressImages = true,
                ImageQuality = 70,
                UnembedFonts = true
            }
        }
    };
    converter.Convert("converted.pdf", options);
}

PdfFormattingOptions

The PdfFormattingOptions class provides different options to change the formatting of the resulting document.

  • CenterWindow whether to position the document’s window in the center of the screen.
  • Direction defines the reading direction of the document: left to right or right to left. Available options are: L2R, R2L
  • DisplayDocTitle whether to display the document title in the window’s title bar.
  • FitWindow whether to resize the document window to fit the first displayed page.
  • HideMenuBar whether to hide the menu bar when the document is active.
  • HideToolBar whether to hide the toolbar when the document is active.
  • HideWindowUI whether to hide user interface elements when the document is active.
  • NonFullScreenPageMode - defines how to display the document when switching from the full-screen mode. Available options are: UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments
  • PageLayout defines the page layout to use when the document is opened. Available options are: Default, SinglePage, OneColumn, TwoColumnLeft, TwoColumnRight, TwoPagesLeft, TwoPagesRight
  • PageMode defines how to display the document when it is opened. Available options are: UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments

The following code snippet shows how to specify PDF formatting options:

using (Converter converter = new Converter("sample.docx"))
{

    PdfConvertOptions options = new PdfConvertOptions
    {        
        PdfOptions = new PdfOptions
        {
            FormattingOptions = new PdfFormattingOptions
            { 
                FitWindow = true,
                HideWindowUI = true,
                PageMode = PdfPageMode.UseThumbs
            }
        }
    };
    converter.Convert("converted.pdf", options);
}