Last active
May 20, 2021 09:33
-
-
Save GroupDocsGists/d5a680abe2fd15a68e8ceca277e3b59c to your computer and use it in GitHub Desktop.
Convert Images 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
// Convert Images to PDF in Java. PNG, WebP, GIF, BMP, TGA and many more ... | |
Converter converter = new Converter("path/image.png"); | |
converter.convert("output/convertedImage.pdf", new PdfConvertOptions()); |
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 JPG, PNG or other Images to PDF in Java. Apply Watermark, Resize, Set DPI and set margins. | |
Converter converter = new Converter("path/image.jpg", new ImageLoadOptions()); | |
// Set the PDF conversion options | |
PdfConvertOptions options = new PdfConvertOptions(); | |
options.setDpi(200); | |
// Set Margins | |
options.setMarginBottom(10); | |
options.setMarginLeft(10); | |
options.setMarginRight(10); | |
options.setMarginTop(10); | |
//options.setRotate(Rotation.On90); // Rotation | |
options.setWidth(640); | |
options.setHeight(426); | |
// Apply watermark to Image in PDF | |
WatermarkOptions watermarkOptions = new WatermarkOptions(); | |
watermarkOptions.setText("Watermark"); | |
watermarkOptions.setColor(Color.WHITE); | |
watermarkOptions.setRotationAngle(-45); | |
watermarkOptions.setTransparency(0.1); | |
watermarkOptions.setLeft(10); | |
watermarkOptions.setTop(75); | |
options.setWatermark(watermarkOptions); | |
// Save the converted PDF file | |
converter.convert("output/convertedJpgToPdfAdv.pdf", options); |
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 JPG Images to PDF in Java. | |
Converter converter = new Converter("path/image.jpg"); | |
converter.convert("output/convertedJpg.pdf", new PdfConvertOptions()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment