Load PDF document with options

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

OptionDescription
FormatThe 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
DefaultFontA default font for PDF document. The specified font will be used if a font is missing. An absolute path to the font file must be provided.
FlattenAllFields Specifies that all fields in the source document should be flattened during conversion.
FontSubstitutesSubstitute specific fonts from the source document.
HidePdfAnnotations  Specifies that annotations in the source document should be hidden.
PasswordA password to unlock the protected document.
RemoveEmbeddedFilesWhether to remove the embedded files from the source document during the conversion.

Flatten all fields

The following code snippet shows how to convert a 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 snippet shows how to convert a 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 snippet shows how to convert a 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 the DefaultFont property of the PdfLoadOptions class to set the default font name. In case the DefaultFont property 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 to word-processing 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 snippet shows how to convert a 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);
}