Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active December 18, 2021 12:38
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/07263be03154d33914f5671e6254513f to your computer and use it in GitHub Desktop.
Save GroupDocsGists/07263be03154d33914f5671e6254513f to your computer and use it in GitHub Desktop.
Convert Source Code Files to PDF in Java
/*
* Renders a Java file into PDF using Java
*/
try (Viewer viewer = new Viewer("path/HelloWorld.java"))
{
PdfViewOptions viewOptions = new PdfViewOptions("path/HelloWorld.pdf");
viewer.view(viewOptions);
}
/*
* Convert Php source file into PDF using Java
*/
try (Viewer viewer = new Viewer("path/source.php"))
{
Security security = new Security();
security.setDocumentOpenPassword("OpEnD0c");
security.setPermissionsPassword("Ple@se");
security.setPermissions(Permissions.ALLOW_ALL ^ Permissions.DENY_PRINTING);
PdfViewOptions viewOptions = new PdfViewOptions("path/php-source.pdf");
viewOptions.setSecurity(security);
viewer.view(viewOptions);
}
/*
* Convert Python source file into PDF using Java
*/
try (Viewer viewer = new Viewer("path/source.py"))
{
PdfViewOptions viewOptions = new PdfViewOptions("path/python-source.pdf");
viewer.view(viewOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment