Do you want to convert image file formats to PDF file formats programmatically? In this blog post, we will learn how to convert BMP to PDF using Java. For this purpose, we will use an enterprise-level Java PDF library that offers a rich stack of features. In addition, we will write a code snippet that automates BMP to PDF conversion programmatically. Therefore, please ensure you have set up Java on your local machine before proceeding.
We will cover the following points:
BMP to PDF conversion API installation
The installation process of this Java PDF library takes a few seconds. This library is lightweight and provides methods to meet your business requirements. Therefore, you can download the API or install it using the following Maven configurations.
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-pdf</artifactId> <classifier>jdk17</classifier> </dependency>
Convert BMP to PDF using Java
Once the installation is completed, you may start writing the code to convert BMP to PDF programmatically.
Please follow the steps and the code snippet mentioned below:
- Instantiate an instance of the Document class.
- Invoke the getPages().add() method to add a page into the document.
- Create an object of the Image class.
- Load sample BMP image file by calling the setFile method.
- Call the setFixWidth method to set the width of the image.
- setFixHeight method will set the height of the image.
- Initialize the constructor of the TextFragment class and invoke the setTitle method to set the title of the image.
- setApplyResolution method sets a boolean value that indicates whether the image use resolution during generation.
- setBlackWhite method sets a boolean value that indicates whether the image is forced to be black-and-white.
- Call getParagraphs().add(image) method to add the image to the page.
- Invoke the save method to save the output as a PDF document
Copy & paste the following code into your main file:
You can see the output in the image below:
Get a Free License
You can avail a free temporary license to try the API without evaluation limitations.
We are ending this blog post here with the hope that you have learned how to convert BMP to PDF using Java programmatically. There are many other prominent methods available that you may find in the documentation. Moreover, this blog post will surely help you if you are looking to automate the BMP to PDF conversion. Moreover, conholdate.com is continuously writing new blog posts. Therefore, please stay in touch for the latest updates.
Ask a question
You can let us know about your questions or queries on our forum.
How do I convert a BMP to PDF?
How do I convert a BMP file?
Please follow this link to convert the BMP file to PDF in Java.