我有一個很大的 pdf 檔案,在上傳到服務器(另一個 wcf 服務)之前,我需要將其拆分為多個 pdf 或塊。我有兩種方法將大檔案(> 2 MB)發送到服務器,方法是將它們分成多個 pdf 或一個 pdf 成塊。有人能告訴我這是如何實作的嗎?我找到了使用 iTextSharp 的文章,但它已被棄用。我不使用許可的。我們有什么可行的方法來實作這一目標嗎?
我遵循了以下文章。但他們使用了 iTextshap,這是一個已棄用的文章。 https://www.c-sharpcorner.com/article/splitting-pdf-file-in-c-sharp-using-itextsharp/
uj5u.com熱心網友回復:
class Program
{
// Output Folder
static string outputFolder = @"D:\PDFSplit\Example\outputFolder";
static void Main(string[] args)
{
// Input Folder
var inputFolder = @"D:\PDFSplit\Example\inputFolder";
// Input File name
var inputPDFFileName = "sample.pdf";
// Input file path
string inputPDFFilePath = Path.Combine(inputFolder, inputPDFFileName);
// Open the input file in Import Mode
PdfDocument inputPDFFile = PdfReader.Open(inputPDFFilePath, PdfDocumentOpenMode.Import);
//Get the total pages in the PDF
var totalPagesInInputPDFFile = inputPDFFile.PageCount;
while(totalPagesInInputPDFFile !=0)
{
//Create an instance of the PDF document in memory
PdfDocument outputPDFDocument = new PdfDocument();
// Add a specific page to the PdfDocument instance
outputPDFDocument.AddPage(inputPDFFile.Pages[totalPagesInInputPDFFile-1]);
//save the PDF document
SaveOutputPDF(outputPDFDocument, totalPagesInInputPDFFile);
totalPagesInInputPDFFile--;
}
}
private static void SaveOutputPDF(PdfDocument outputPDFDocument,int pageNo)
{
// Output file path
string outputPDFFilePath = Path.Combine(outputFolder, pageNo.ToString() ".pdf");
//Save the document
outputPDFDocument.Save(outputPDFFilePath);
}
}
uj5u.com熱心網友回復:
嘗試使用流,例如 StreamReader。
在這里看到肉背心的回答
和檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/346229.html
下一篇:UWPC#將png轉換為pdf
