翻譯|行業資訊|編輯:胡濤|2024-03-19 13:08:42.180|閱讀 79 次
概述:本文主要介紹在文檔控件Spire.PDF for .NET中,如何將PDF拆分為多個PDF文件,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.PDF for .NET 是一款獨立 PDF 控件,用于 .NET 程序中創建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發人員可以新建一個 PDF 文檔或者對現有的 PDF 文檔進行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下載 Spire.PDF for java下載
首先,您需要將 Spire.PDF for .NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.PDF
Spire.PDF提供Split()方法將多頁PDF文檔分割成多個單頁文件。以下是詳細步驟。
[C#]
using System; using Spire.Pdf; namespace SplitPDFIntoIndividualPages { class Program { static void Main(string[] args) { //Specify the input file path String inputFile = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf"; //Specify the output directory String outputDirectory = "C:\\Users\\Administrator\\Desktop\\Output\\"; //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a PDF file doc.LoadFromFile(inputFile); //Split the PDF to one-page PDFs doc.Split(outputDirectory + "output-{0}.pdf", 1); } } }
【VB.NET】
Imports System Imports Spire.Pdf Namespace SplitPDFIntoIndividualPages Class Program Shared Sub Main(ByVal args() As String) 'Specify the path of the input file Dim inputFile As String = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf" 'Specify the output directory Dim outputDirectory As String = "C:\\Users\\Administrator\\Desktop\\Output\\" 'Create a PdfDocument object Dim doc As PdfDocument = New PdfDocument() 'Load a PDF file doc.LoadFromFile(inputFile) 'Split the PDF to one-page PDFs doc.Split(outputDirectory + "output-{0}.pdf", 1) End Sub End Class End Namespace
沒有提供按頁面范圍拆分 PDF 文檔的直接方法。為此,我們創建兩個或多個新的 PDF 文檔,并將源文檔中的頁面或頁面范圍導入到其中。以下是詳細步驟。
[C#]
using Spire.Pdf; using System; namespace SplitPdfByPageRanges { class Program { static void Main(string[] args) { //Specify the input file path String inputFile = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf"; //Specify the output directory String outputDirectory = "C:\\Users\\Administrator\\Desktop\\Output\\"; //Load the source PDF file while initialing the PdfDocument object PdfDocument sourceDoc = new PdfDocument(inputFile); //Create two additional PdfDocument objects PdfDocument newDoc_1 = new PdfDocument(); PdfDocument newDoc_2 = new PdfDocument(); //Insert the first page of source file to the first document newDoc_1.InsertPage(sourceDoc, 0); //Insert the rest pages of source file to the second document newDoc_2.InsertPageRange(sourceDoc, 1, sourceDoc.Pages.Count - 1); //Save the two documents as PDF files newDoc_1.SaveToFile(outputDirectory + "output-1.pdf"); newDoc_2.SaveToFile(outputDirectory + "output-2.pdf"); } } }
【VB.NET】
Imports Spire.Pdf Imports System Namespace SplitPdfByPageRanges Class Program Shared Sub Main(ByVal args() As String) 'Specify the input file path Dim inputFile As String = "C:\\Users\\Administrator\\Desktop\\Terms of Service.pdf" 'Specify the output directory Dim outputDirectory As String = "C:\\Users\\Administrator\\Desktop\\Output\\" 'Load the source PDF file while initialing the PdfDocument object Dim sourceDoc As PdfDocument = New PdfDocument(inputFile) 'Create two additional PdfDocument objects Dim NewDoc_1 As PdfDocument = New PdfDocument() Dim NewDoc_2 As PdfDocument = New PdfDocument() 'Insert the first page of source file to the first document NewDoc_1.InsertPage(sourceDoc, 0) 'Insert the rest pages of source file to the second document NewDoc_2.InsertPageRange(sourceDoc, 1, sourceDoc.Pages.Count - 1) 'Save the two documents as PDF files NewDoc_1.SaveToFile(outputDirectory + "output-1.pdf") NewDoc_2.SaveToFile(outputDirectory + "output-2.pdf") End Sub End Class End Namespace
以上便是如何將PDF拆分為多個PDF文件,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn