翻譯|行業(yè)資訊|編輯:胡濤|2024-12-03 10:38:05.860|閱讀 89 次
概述:在本文中,您將學(xué)習(xí)如何通過壓縮內(nèi)容來擴(kuò)大 PDF 頁邊距。歡迎查閱~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
PDF 頁邊距是正文內(nèi)容和頁面邊緣之間的空白。與 Word 不同,PDF 文檔中的頁邊距不易修改,因?yàn)?Adobe 不提供任何功能供用戶自由操作頁邊距。但是,您可以更改頁面縮放比例(放大/壓縮內(nèi)容)或裁剪頁面以獲得合適的頁邊距。在本文中,您將學(xué)習(xí)如何通過壓縮內(nèi)容來擴(kuò)大 PDF 頁邊距。
Spire.PDF for .NET 是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發(fā)人員可以新建一個(gè) PDF 文檔或者對(duì)現(xiàn)有的 PDF 文檔進(jìn)行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時(shí)適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
步驟 1:創(chuàng)建一個(gè) PdfDocument 對(duì)象來加載原始 PDF 文檔。
PdfDocument origDoc = new PdfDocument(); origDoc.LoadFromFile("sample.pdf");
第 2 步:創(chuàng)建另一個(gè) PdfDocument 對(duì)象。
PdfDocument destDoc = new PdfDocument();
步驟 3:設(shè)置您想要添加到現(xiàn)有 PDF 文檔邊距的增量。
float top = 50; float bottom = 50; float left = 50; float right = 50;
步驟 4:將原始文檔中的壓縮內(nèi)容傳輸?shù)叫碌?PDF 文檔。
foreach (PdfPageBase page in origDoc.Pages) { PdfPageBase newPage = destDoc.Pages.Add(page.Size, new PdfMargins(0)); newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width, (page.ActualSize.Height - top - bottom) / page.ActualSize.Height); newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(left, top)); }
步驟 5:保存到文件。
destDoc.SaveToFile("result.pdf", FileFormat.PDF);
原始PDF:
結(jié)果:
完整代碼:
[C#]
using Spire.Pdf; using Spire.Pdf.Graphics; using System.Drawing; namespace ChangeMargins { class Program { static void Main(string[] args) { PdfDocument origDoc = new PdfDocument(); origDoc.LoadFromFile("sample.pdf"); PdfDocument destDoc = new PdfDocument(); float top = 50; float bottom = 50; float left = 50; float right = 50; foreach (PdfPageBase page in origDoc.Pages) { PdfPageBase newPage = destDoc.Pages.Add(page.Size, new PdfMargins(0)); newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width, (page.ActualSize.Height - top - bottom) / page.ActualSize.Height); newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(left, top)); } destDoc.SaveToFile("result.pdf", FileFormat.PDF); } } }
Imports Spire.Pdf Imports Spire.Pdf.Graphics Imports System.Drawing Namespace ChangeMargins Class Program Private Shared Sub Main(args As String()) Dim origDoc As New PdfDocument() origDoc.LoadFromFile("sample.pdf") Dim destDoc As New PdfDocument() Dim top As Single = 50 Dim bottom As Single = 50 Dim left As Single = 50 Dim right As Single = 50 For Each page As PdfPageBase In origDoc.Pages Dim newPage As PdfPageBase = destDoc.Pages.Add(page.Size, New PdfMargins(0)) newPage.Canvas.ScaleTransform((page.ActualSize.Width - left - right) / page.ActualSize.Width, (page.ActualSize.Height - top - bottom) / page.ActualSize.Height) newPage.Canvas.DrawTemplate(page.CreateTemplate(), New PointF(left, top)) Next destDoc.SaveToFile("result.pdf", FileFormat.PDF) End Sub End Class End Namespace
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢慧都在線客服 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn