PDF is a popular format that many organizations use for sharing documents over the internet. You might find yourself in situations where you need to create a PDF file from images of scanned documents or invoices. In light of this, this article will teach you how to convert images to PDF format using C++.
C++ API for Converting Images to PDF Format
Aspose.PDF for C++ is a C++ library that allows you to create, read and modify PDF documents. Furthermore, the API supports converting images to PDF files. You can either install the API through NuGet or download it directly from the downloads section.
PM> Install-Package Aspose.PDF.Cpp
Convert an Image to PDF File using C++
The following are the steps to convert an image to PDF format.
- Create an instance of the Document class.
- Add a blank page to the document.
- Set margins and crop box.
- Create an instance of the Image class.
- Specify the path of the image using the Image->set_File(System::String value) method.
- Add the image to the PDF page using the Page->get_Paragraphs()->Add(System::SharedPtr paragraph) method.
- Save the PDF file using the Document->Save(System::String outputFileName) method.
The following sample code demonstrates how to convert an image to a PDF file using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
In this article, you have learned how to convert images to PDF format using C++. You have seen the complete code snippet along with the steps required to achieve this. Aspose.PDF for C++ provides many additional features for enhancing your PDF-related workflows. You can explore the API in detail by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.