翻譯|行業(yè)資訊|編輯:胡濤|2024-03-19 13:08:42.180|閱讀 79 次
概述:本文主要介紹在文檔控件Spire.PDF for .NET中,如何將PDF拆分為多個(gè)PDF文件,歡迎查閱~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Spire.PDF for .NET 是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類(lèi)庫(kù),開(kāi)發(fā)人員可以新建一個(gè) PDF 文檔或者對(duì)現(xiàn)有的 PDF 文檔進(jìn)行處理,且無(wú)需安裝 Adobe Acrobat。
E-iceblue 功能類(lèi)庫(kù)Spire 系列文檔處理組件均由中國(guó)本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國(guó)家的技術(shù)或法律法規(guī)限制,同時(shí)適配國(guó)產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國(guó)產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下載 Spire.PDF for java下載
首先,您需要將 Spire.PDF for .NET 包中包含的 DLL 文件添加為 .NET 項(xiàng)目中的引用。DLL 文件可以從此鏈接下載或通過(guò)NuGet安裝。
PM> Install-Package Spire.PDF
Spire.PDF提供Split()方法將多頁(yè)P(yáng)DF文檔分割成多個(gè)單頁(yè)文件。以下是詳細(xì)步驟。
[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
沒(méi)有提供按頁(yè)面范圍拆分 PDF 文檔的直接方法。為此,我們創(chuàng)建兩個(gè)或多個(gè)新的 PDF 文檔,并將源文檔中的頁(yè)面或頁(yè)面范圍導(dǎo)入到其中。以下是詳細(xì)步驟。
[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拆分為多個(gè)PDF文件,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(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