string[] htmlTextArr=Regex.Split(htmlText,"##",RegexOptions.IgnoreCase);
MemoryStream outputStream = new MemoryStream();
Document doc = new Document();
PdfWriter writer =PdfWriter.GetInstance(doc,outputStream);
PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ,0,doc.PageSize.Height,1f);
doc.open();
for(int i=0;i<htmlTextArr.Length;i++){
byte[] data=Encoding.UTF8.GetBytes(htmlTextArr[i]);
MemoryStream msInput =new MemoryStream(data);
XMLWorkerHelper.GetInstance().ParseXHtml(writer,doc,msInput,null,Encoding.UTF8,new UnicodeFontFactory());
if(i<htmlTextArr.Length-1){
doc.NewPage();
}
if(i==htmlTextArr.Length-1){
PdfAction action =PdfAction.GotoLocalPage(1,pdfDest,writer);
writer.SetOpenAction(action);
doc.Close();
msInput.Close();
outputStream.Close();
}
}
利用iTextSharp实现分页功能
最新推荐文章于 2025-06-27 11:26:37 发布