Convert to PDF with advanced options

GroupDocs.Conversion provides the PdfConvertOptions class to give you better control over conversion results when converting to PDF. Along with common convert options, the PdfConvertOptions has the following additional options:

  • setFormat desired result document type. Available options are: Pdf, Epub, Xps, Tex, Ps, Pcl
  • setWidth specifies desired image width after conversion.
  • setHeight specifies desired image height after conversion.
  • setDpi specifies desired page DPI after conversion.
  • setPassword specifies the password to protect the document.
  • setMarginTop specifies desired page top margin after conversion.
  • setMarginBottom specifies desired page bottom margin after conversion.
  • setMarginLeft specifies desired page left margin after conversion.
  • setMarginRight specifies desired page right margin after conversion.
  • setPdfOptions specifies PDF-specific convert options.
  • setRotate specifies page rotation. Available options are: None, On90, On180, On270.

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

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.convert.Rotation;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;
...
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setPassword("12345");

Converter converter = new Converter("sample.docx");
PdfConvertOptions options = new PdfConvertOptions();
options.setPageNumber(2);
options.setPagesCount(1);
options.setRotate(Rotation.On180);
options.setDpi(300);
options.setWidth(1024);
options.setHeight(768);

converter.convert("converted.pdf", options);

PdfOptions

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

PdfOptimizationOptions

The PdfOptimizationOptions class allows to specify options for adjusting the PDF conversion process and improving its speed.

PdfFormattingOptions

The PdfFormattingOptions class provides different options to change the document look.

  • setCenterWindow specifies whether a position of the document’s window will be centered on the screen.
  • setDirection sets reading order of text: L2R (left to right) or R2L (right to left). Available options are: L2R, R2L.
  • setDisplayDocTitle specifies whether the document’s window title bar should display the document title.
  • setFitWindow specifies whether the document window must be resized to fit the first displayed page.
  • setHideMenuBar specifies whether the menu bar should be hidden when the document is active.
  • setHideToolBar specifies whether the toolbar should be hidden when the document is active.
  • setHideWindowUI specifies whether user interface elements should be hidden when the document is active
  • setNonFullScreenPageMode specifies how to display the document on exiting full-screen mode. Available options are: UseNone, UseOutlines, UseThumbs, FullScreen, UseOC, UseAttachments.
  • setPageLayout sets page layout which shall be used when the document is opened. Available options are: Default, SinglePage, OneColumn, TwoColumnLeft, TwoColumnRight, TwoPagesLeft, TwoPagesRight.
  • setPageMode - specifies how the document should be displayed when opened.