Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 27, 2021 16:28
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 aspose-com-gists/1da17d20a8e3939c2a596646577e0370 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1da17d20a8e3939c2a596646577e0370 to your computer and use it in GitHub Desktop.
Read the complete article about converting images to PDF format using C++ by visiting the following link.
https://blog.aspose.com/2021/06/24/convert-images-to-pdf-format-using-cpp/
// Create an instance of the Document class
auto pdfDocument = MakeObject<Document>();
// Add a page
System::SharedPtr<Page> page = pdfDocument->get_Pages()->Add();
// Set margins
page->get_PageInfo()->get_Margin()->set_Bottom(0);
page->get_PageInfo()->get_Margin()->set_Top(0);
page->get_PageInfo()->get_Margin()->set_Left(0);
page->get_PageInfo()->get_Margin()->set_Right(0);
// Set CropBox
page->set_CropBox(MakeObject<Aspose::Pdf::Rectangle>(0, 0, 400, 400));
// Create an instance of the Image class
System::SharedPtr<Aspose::Pdf::Image> image = MakeObject<Aspose::Pdf::Image>();
// Specify the image path
image->set_File(u"SourceDirectory\\Images\\AsposeLogo.png");
// Add the image to the PDF page
page->get_Paragraphs()->Add(System::DynamicCast<BaseParagraph>(image));
// Save the PDF file
pdfDocument->Save(u"OutputDirectory\\Image2PDF.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment