Load PDF document with options

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

  • 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;
... 
PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.setFlattenAllFields(true);

Converter converter = new Converter("sample.pdf", loadOptions);
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:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WordProcessingConvertOptions;
import com.groupdocs.conversion.options.load.PdfLoadOptions;
... 
PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.setHidePdfAnnotations(true);

Converter converter = new Converter("sample.pdf", loadOptions);
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:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WordProcessingConvertOptions;
import com.groupdocs.conversion.options.load.PdfLoadOptions;
... 
PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.setRemoveEmbeddedFiles(true);

Converter converter = new Converter("sample.pdf", loadOptions);
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
converter.convert("converted.docx", options);