Load PDF document with options

The GroupDocs.Conversion for Java API offers advanced capabilities for loading PDF documents with customizable options. Using the PdfLoadOptions class, developers can specify precise configurations, such as enabling password protection for encrypted PDFs, selectively loading specific pages, and defining other document-specific properties. This feature facilitates optimized workflows in Java applications, enabling seamless handling of diverse PDF files during conversion.

The API provides robust error handling, ensuring smooth operation when processing malformed or restricted PDF documents. Moreover, the PdfLoadOptions class can be integrated with other API functionalities to support a wide range of output formats, maintaining high fidelity during the conversion process. The following options could be set:

OptionDescription
setFormat()Allows you to specify explicitly the type of the source document. Available options are: Pdf, Epub, Xps, Tex, Ps, Pcl.
setRemoveEmbeddedFiles()Whether to remove the embedded files from the source document during the conversion.
setPassword()Specifies a password to unlock the protected document.
setHidePdfAnnotations()Specifies that annotations in the source document should be hidden.
setFlattenAllFields()Specifies that all fields in the source document should be flattened during the conversion.

Flatten all fields

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WordProcessingConvertOptions;
import com.groupdocs.conversion.options.load.PdfLoadOptions;

public class ConvertPdfAndFlattenAllFields {
    public static void convert() {
        PdfLoadOptions loadOptions = new PdfLoadOptions();
        loadOptions.setFlattenAllFields(true);

        try(Converter converter = new Converter("sample.pdf", () -> loadOptions)) {
            WordProcessingConvertOptions options = new WordProcessingConvertOptions();
            converter.convert("converted_with_fields.docx", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.pdf is sample file used in this example. Click here to download it.

converted_with_fields.docx is converted DOCX document. Click here to download it.

Hide annotations

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WordProcessingConvertOptions;
import com.groupdocs.conversion.options.load.PdfLoadOptions;

public class ConvertPdfAndHideAnnotations {
    public static void convert() {
        PdfLoadOptions loadOptions = new PdfLoadOptions();
        loadOptions.setHidePdfAnnotations(true);

        try(Converter converter = new Converter("sample.pdf", () -> loadOptions)) {
            WordProcessingConvertOptions options = new WordProcessingConvertOptions();
            converter.convert("converted_without_annotations.docx", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.pdf is sample file used in this example. Click here to download it.

converted_without_annotations.docx is converted DOCX document. Click here to download it.

Remove embedded files

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WordProcessingConvertOptions;
import com.groupdocs.conversion.options.load.PdfLoadOptions;

public class ConvertPdfAndRemoveEmbeddedFiles {
    public static void convert() {
        PdfLoadOptions loadOptions = new PdfLoadOptions();
        loadOptions.setRemoveEmbeddedFiles(true);

        try(Converter converter = new Converter("sample.pdf", () -> loadOptions)) {
            WordProcessingConvertOptions options = new WordProcessingConvertOptions();
            converter.convert("converted_without_fields.docx", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

sample.pdf is sample file used in this example. Click here to download it.

converted_without_fields.docx is converted DOCX document. Click here to download it.