翻譯|使用教程|編輯:李顯亮|2020-10-23 10:13:42.797|閱讀 634 次
概述:在本文中,將在簡單而基本的PDF旋轉(zhuǎn)功能示例的幫助下,瀏覽PDF頁面,圖像或文本旋轉(zhuǎn)方案,包括旋轉(zhuǎn)PDF文檔的所有頁面、在PDF上旋轉(zhuǎn)圖像、旋轉(zhuǎn)PDF文檔上的文本等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在本文中,讓我們探討與PDF文檔旋轉(zhuǎn)相關(guān)的場景,可以在基于.NET框架的應(yīng)用程序中使用C#或VB.NET以編程方式旋轉(zhuǎn)整個頁面或PDF頁面內(nèi)容,包括文本或圖像。
此外,本文將在簡單而基本的PDF旋轉(zhuǎn)功能示例的幫助下,瀏覽以下PDF頁面,圖像或文本旋轉(zhuǎn)方案:
目前,.NET版Aspose.PDF升級到v20.10版,新增支持ZUGFeRD附件,優(yōu)化添加簽名功能嗎,修復(fù)XPS到PDF轉(zhuǎn)換異常等諸多Bug問題,感興趣的朋友可點擊下方按鈕下載最新版。
讓我們假設(shè)通過掃描某些文檔(以特定角度掃描所有圖像)創(chuàng)建的PDF文檔。就像所有頁面都是上下顛倒一樣,您需要在C#或VB.NET應(yīng)用程序中旋轉(zhuǎn)PDF文檔的所有頁面。同樣,可能有成千上萬的相關(guān)用例需要旋轉(zhuǎn)PDF文件。您可以按照以下步驟旋轉(zhuǎn)PDF文件的所有頁面:
下面的代碼段顯示了如何使用C#或VB.NET旋轉(zhuǎn)PDF文件的所有頁面:
// Load input PDF document Document document = new Document(dataDir + "Rotate.pdf"); // Iterate through each page of PDF foreach(Page page in document.Pages) { // Rotate the PDF document on desired angle page.Rotate = Rotation.on180; } // Save output rotated PDF file document.Save(dataDir + "Rotated.pdf");
PDF文檔中的旋轉(zhuǎn)應(yīng)用于頁面級別。因此,您還可以根據(jù)需要旋轉(zhuǎn)PDF文件的特定頁面。您只需要選擇要應(yīng)用旋轉(zhuǎn)的頁碼即可。以下步驟說明了如何旋轉(zhuǎn)PDF文件的某些頁面:
以下代碼段闡述了如何使用C#或VB.NET旋轉(zhuǎn)PDF文檔中的特定頁面或特定頁面:
// Load input PDF document Document document = new Document(dataDir + "Rotate.pdf"); // Specify the page numbers you want to apply rotation on int[] pages = { 1, 3, 7 }; // Iterate through particular pages foreach (Page page in document.Pages) { foreach (int match in pages) { if (page.Number == match) { // Rotate the page page.Rotate = Rotation.on90; } } } // Save rotated PDF document document.Save(dataDir + "Rotated.pdf");
在PDF文檔中添加文本時,可以旋轉(zhuǎn)不同角度的文本。在PDF文檔中添加一些水印文本時,此文本旋轉(zhuǎn)可能更相關(guān)。讓我們在頁面上的特定坐標(biāo)處添加一些文本,然后將文本對角旋轉(zhuǎn)45度。
下面的代碼段顯示了如何使用C#或VB.NET旋轉(zhuǎn)PDF文檔中的文本:
// Initialize document Document pdfDocument = new Document(); // Get particular page Page pdfPage = pdfDocument.Pages.Add(); // Create text fragment TextFragment tf = new TextFragment("Rotated text"); // Add text at specific loaction on the page tf.Position = (new Position(200, 600)); // Set text properties tf.TextState.FontSize = 12; tf.TextState.Font = FontRepository.FindFont("TimesNewRoman"); tf.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray; tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red; tf.TextState.Rotation = 45; tf.TextState.Underline = true; // Create TextBuilder object TextBuilder textBuilder = new TextBuilder(pdfPage); // Append the text fragment to the PDF page textBuilder.AppendText(tf); // Save document pdfDocument.Save(dataDir + "Text_Rotated.pdf");
可以在PDF文檔中添加或插入圖像時旋轉(zhuǎn)PDF文檔中的圖像。當(dāng)您要更新或更改圖像方向時,這可能會很有幫助。您可以按照以下步驟在PDF頁面上旋轉(zhuǎn)圖像:
以下代碼演示了如何使用C#或VB.NET以編程方式旋轉(zhuǎn)PDF文檔中的圖像或圖片:
// Open document Document pdfDocument = new Document(dataDir + "Image.pdf"); // Create image stamp ImageStamp imageStamp = new ImageStamp(dataDir + "Image.jpg"); imageStamp.XIndent = 100; imageStamp.YIndent = 100; imageStamp.Height = 300; imageStamp.Width = 300; imageStamp.Rotate = Rotation.on90; imageStamp.Opacity = 0.5; // Add stamp to particular page pdfDocument.Pages[1].AddStamp(imageStamp); dataDir = dataDir + "RotatedImage.pdf"; // Save output document pdfDocument.Save(dataDir);
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn