Load PDF document with options

GroupDocs.Conversion provides PdfLoadOptions to give you control over how source PDF document will be processed. The following options could be set:

  • Format - the document type is auto detected during loading, however you can specify explicitly the type of the source document. Available options are: Pdf, Epub, Xps, Tex, Ps, Pcl
  • RemoveEmbeddedFiles - specifies to remove embedded files from source document during conversion
  • Password - password to unlock protected document
  • HidePdfAnnotations -  specifies that annotations in the source document must be hidden
  • FlattenAllFields - specifies that all fields in the source document will be flatten during conversion

Flatten all fields

The following code sample shows how to convert PDF document and flatten all fields:

Contracts.Func<LoadOptions> getLoadOptions = () => new PdfLoadOptions
{
    FlattenAllFields = true
};
using (Converter converter = new Converter("sample.pdf", getLoadOptions))
{
    WordProcessingConvertOptions options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

Hide annotations

The following code sample shows how to convert PDF document and hide annotations:

Contracts.Func<LoadOptions> getLoadOptions = () => new PdfLoadOptions
{
    HidePdfAnnotations = true
};
using (Converter converter = new Converter("sample.pdf", getLoadOptions))
{
    WordProcessingConvertOptions options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

Remove embedded files

The following code sample shows how to convert PDF document and remove embedded files:

Contracts.Func<LoadOptions> getLoadOptions = () => new PdfLoadOptions
{
    RemoveEmbeddedFiles = true
};
using (Converter converter = new Converter("sample.pdf", getLoadOptions))
{
    WordProcessingConvertOptions options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

Set Default Font

GroupDocs.Conversion for .NET allows you to set a default font name when a font is not available in the document. You can use DefaultFont property of PdfLoadOptions class to set the default font name. In case DefaultFont is not set the Times New Roman font will be used. The following code snippet shows how to set a default font name when converting from PDF into to wordprocessing document:

Contracts.Func<LoadOptions> getLoadOptions = () => new PdfLoadOptions
{
    DefaultFont = "Helvetica"
};
using (Converter converter = new Converter("sample.pdf", getLoadOptions))
{
    WordProcessingConvertOptions options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

Specify font substitution

The following code sample shows how to convert Pdf document and specify font substitution for missing fonts:

Contracts.Func<LoadOptions> getLoadOptions = () => new PdfLoadOptions
{
    FontSubstitutes = new List<FontSubstitute>
    {
        FontSubstitute.Create("Tahoma", "Arial"),
        FontSubstitute.Create("Times New Roman", "Arial"),
    }
};
using (Converter converter = new Converter("sample.pdf", getLoadOptions))
{
    PdfConvertOptions options = new WordProcessingConvertOptions();
    converter.Convert("converted.docx", options);
}

© Aspose Pty Ltd 2001-2022. All Rights Reserved.