Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active January 28, 2023 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/7e0d36b77775de925ed754afa409b42a to your computer and use it in GitHub Desktop.
Save GroupDocsGists/7e0d36b77775de925ed754afa409b42a to your computer and use it in GitHub Desktop.
View Word Documents as PDF in Java
// How to view Word Documents as PDF in Java
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.PdfViewOptions;
...
try (Viewer viewer = new Viewer("path/document.docx"))
{
viewer.view(new PdfViewOptions("path/Word-Document.pdf"));
}
// How to view Word Documents as Protected PDF & Deny Printing in Java
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.options.PdfViewOptions;
import com.groupdocs.viewer.options.Permissions;
import com.groupdocs.viewer.options.Security;
...
Security security = new Security();
security.setDocumentOpenPassword("opening-pass");
security.setPermissionsPassword("permission-pass");
security.setPermissions(Permissions.ALLOW_ALL ^ Permissions.DENY_PRINTING);
PdfViewOptions viewOptions = new PdfViewOptions("path/Word-Document.pdf");
viewOptions.setSecurity(security);
try (Viewer viewer = new Viewer("path/document.docx"))
{
viewer.view(viewOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment