Skip to content

Instantly share code, notes, and snippets.

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/9c56e3d998ac1ca9f176da93adcb24c1 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9c56e3d998ac1ca9f176da93adcb24c1 to your computer and use it in GitHub Desktop.
Rotate PDF Pages, Text or Image using C++
Rotate PDF Pages, Text or Image using C++
// Open the source PDF document
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf");
// Loop through the pages
for (System::SharedPtr<Page> page : pdfDocument->get_Pages())
{
// Rotate page
page->set_Rotate(Aspose::Pdf::Rotation::on180);
}
// Save the PDF file
pdfDocument->Save(u"OutputDirectory\\Rotated_out.pdf", SaveFormat::Pdf);
// Open the source PDF document
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\Sample 1.pdf");
// Create ImageStamp object
System::SharedPtr<ImageStamp> imageStamp = MakeObject<ImageStamp>(u"SourceDirectory\\aspose.png");
// Set ImageStamp properties
imageStamp->set_XIndent(250);
imageStamp->set_YIndent(350);
imageStamp->set_Height(100);
imageStamp->set_Width(300);
imageStamp->set_Rotate(Rotation::on90);
imageStamp->set_Opacity(0.5);
// Add ImageStamp to the page
pdfDocument->get_Pages()->idx_get(1)->AddStamp(imageStamp);
// Save the PDF file
pdfDocument->Save(u"OutputDirectory\\Rotated_image_out.pdf", SaveFormat::Pdf);
// Create an instance of the Document class
auto pdfDocument = MakeObject<Document>();
// Add new page
System::SharedPtr<Page> page = pdfDocument->get_Pages()->Add();
// Create TextFragment object
System::SharedPtr<TextFragment> textFragment = MakeObject<TextFragment>(u"Rotated Text");
// Set the position of the text
textFragment->set_Position(MakeObject<Position>(200, 600));
// Set text properties
textFragment->get_TextState()->set_FontSize(12);
textFragment->get_TextState()->set_Font(FontRepository::FindFont(u"TimesNewRoman"));
textFragment->get_TextState()->set_BackgroundColor(Aspose::Pdf::Color::get_LightGray());
textFragment->get_TextState()->set_ForegroundColor(Aspose::Pdf::Color::get_Red());
textFragment->get_TextState()->set_Rotation(45);
textFragment->get_TextState()->set_Underline(true);
// Create TextBuilder object
System::SharedPtr<TextBuilder> textBuilder = MakeObject<TextBuilder>(page);
// Add texc to the page
textBuilder->AppendText(textFragment);
// Save the PDF file
pdfDocument->Save(u"OutputDirectory\\Rotated_text_out.pdf", SaveFormat::Pdf);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment