Related blog post: Convert Source Code to PDF in Java
Last active
December 18, 2021 12:38
-
-
Save GroupDocsGists/07263be03154d33914f5671e6254513f to your computer and use it in GitHub Desktop.
Convert Source Code Files to PDF in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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