PdfReader按页将PDF切割成多个PDF

private MemoryStream GetNewPdfByPageNum(PdfReader pdfReader, int pageNum)
{
MemoryStream memoryStream = new MemoryStream();
try
{
iTextSharp.text.Document document = new iTextSharp.text.Document();
PdfCopy copy = new PdfCopy(document, memoryStream) { CloseStream = false };
document.Open();
copy.AddPage(copy.GetImportedPage(pdfReader, pageNum));
document.Close();
}
catch { }
return memoryStream;
}
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var pdfBytes = new WebClient().DownloadData("http://....pdf");
var pdfReader = new PdfReader(pdfBytes);
for (int i = ; i < pdfReader.NumberOfPages + ; i++)
{
var memoryStream = GetNewPdfByPageNum(pdfReader, i);
FileStream file = new FileStream($"{desktopPath}/page{i}.pdf", FileMode.CreateNew);
memoryStream.WriteTo(file);
file.Dispose();
}
pdfReader.Close();
上一篇:iOS常用第三方框架大全


下一篇:QComboBox列表项高度设置