C# based on PdfSharp to split pdf files and get MemoryStream C#基于PdfSharp拆分pdf,并生成MemoryStream
程序员文章站
2022-05-28 20:57:35
install-package PdfSharp -v 1.51.5185-beta ......
install-package pdfsharp -v 1.51.5185-beta
using system; using pdfsharp.pdf; using system.io; using pdfsharp.pdf.io; using system.collections.generic; namespace consoleapp2 { class program { static void main(string[] args) { string rawpdffile = @"c:\users\ffu\downloads\2.pdf"; ppfsharpexample(rawpdffile); console.readline(); } static void ppfsharpexample(string rawpdffile) { pdfdocument inputdocument = pdfreader.open(rawpdffile, pdfdocumentopenmode.import); int count = inputdocument.pagecount; list<memorystream> mslist = new list<memorystream>(); for (int idx = 0; idx < count; idx++) { pdfpage page = inputdocument.pages[idx]; pdfdocument outputdocument = new pdfdocument(); outputdocument.addpage(page); memorystream ms = new memorystream(); outputdocument.save(ms); string splitpdf =idx+1+"splitpdf"+ guid.newguid().tostring().replace("-", "") + ".pdf"; outputdocument.save(splitpdf); mslist.add(ms); console.writeline(ms.toarray().length); } } } }
上一篇: 花菜青椒炒里脊做法,花菜做法大全!