翻譯|使用教程|編輯:李顯亮|2021-06-01 09:33:14.417|閱讀 227 次
概述:在某些情況下,可能需要修復反向掃描的 PDF 文檔。為此,本文將教您如何使用 C++ 以編程方式旋轉 PDF 頁面、文本和圖像。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在某些情況下,可能需要修復反向掃描的 PDF 文檔。可以通過旋轉文檔頁面來修復此類文檔??赡苓€想通過旋轉將文本或圖像水印添加到 PDF 文檔中。為此,本文將介紹如何使用 C++ 以編程方式旋轉 PDF 頁面、文本和圖像。
Aspose.PDF for C++是一個 C++ 庫,允許您創建、閱讀和更新 PDF 文檔。除此之外,API 還支持旋轉 PDF 頁面、文本和圖像。點擊下方按鈕可下載試用。
使用 Aspose.PDF for C++ 旋轉頁面輕而易舉。只需幾行代碼,您就可以旋轉 PDF 文檔的所有頁面。以下是使用 C++ 旋轉 PDF 頁面的步驟。
以下示例代碼顯示了如何使用 C++ 旋轉 PDF 頁面。
// Open the source PDF document auto pdfDocument = MakeObject(u"SourceDirectory\\Sample 1.pdf"); // Loop through the pages for (System::SharedPtrpage : 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);
在向 PDF 文檔添加文本時,您可以更改許多文本屬性,包括其角度。在以下示例中,我們將向 PDF 頁面添加文本并將其旋轉 45 度角。以下是實現這一目標的步驟。
以下示例代碼演示了如何使用 C++ 旋轉 PDF 頁面上的文本。
// Create an instance of the Document class auto pdfDocument = MakeObject(); // Add new page System::SharedPtrpage = pdfDocument->get_Pages()->Add(); // Create TextFragment object System::SharedPtrtextFragment = MakeObject(u"Rotated Text"); // Set the position of the text textFragment->set_Position(MakeObject(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::SharedPtrtextBuilder = MakeObject(page); // Add texc to the page textBuilder->AppendText(textFragment); // Save the PDF file pdfDocument->Save(u"OutputDirectory\\Rotated_text_out.pdf", SaveFormat::Pdf);
在向 PDF 文檔添加圖像時,您可以設置許多屬性,如高度、寬度、不透明度、旋轉度等。在本示例中,我們將向 PDF 頁面添加圖像并將其旋轉 90 度。以下是在 PDF 頁面上旋轉圖像的步驟。
以下示例代碼顯示了如何使用 C++ 旋轉 PDF 頁面上的圖像。
// Open the source PDF document auto pdfDocument = MakeObject(u"SourceDirectory\\Sample 1.pdf"); // Create ImageStamp object System::SharedPtrimageStamp = MakeObject(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);
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn