本文介绍了如何使用itextsharp将aspx页面转换为多页的pdf文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用itextsharp我正在将aspx页面转换为pdf文档,但是在pdf文件中每次只创建一个页面,但仍然在aspx页面中存在数据,而这些页面并非在pdf文件中创建。我正在使用C#使用asp.net ,请尽早给出解决方案



private void ConvertPDF()

{

try

{

string path = Server.MapPath(〜/ Img / Student Photos // PDFFiles //);

path = path + objbllpreadm .objELLPreAdmission.User_id +。pdf;



if(File.Exists(path))

{

File.Delete(路径);

}



attchmt = objbllpreadm.objELLPreAdmission.User_id +。pdf;

string filename1 =;

filename1 = objbllpreadm.objELLPreAdmission.User_id +。pdf;



回复。 ContentType =应用程序ion / pdf;

Response.AddHeader(content-disposition,attachment; filename =+ filename1);

Response.Cache.SetCacheability(HttpCacheability.NoCache );

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);



this.Page.RenderControl(hw);

var output = new FileStream(path,FileMode.Create);



StringReader sr = new StringReader(sw.ToString());



iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3,0f, 10f,10f,0f);





HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter。 GetInstance(pdfDoc,Response.OutputStream);

iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc,output);



pdfDoc.Open();

htmlparser.Parse(sr);



pdfDoc.Close();

Response.Write(pdfDoc);

HttpContext.Current.ApplicationInstance.CompleteRequest();

}

catch(Exception exp )

{

var ErrorMessage = new JavaScriptSerializer()。Serialize(exp.Message.ToString());

ShowAlertMessage(ErrorMessage);

}

}





我用于转换的上述方法aspx页面到pdf文档,代码完全运行,没有错误抛出,运行代码后将下载一个包含2个页面的pdf文件,另外一个文件将在〜/ Img / Student Photos // PDFFiles //文件夹中创建其中包含单页...剩余数据未来

using itextsharp i am converting aspx page to pdf document,but in pdf file only one page is creating every time but still data is there in aspx page which was not created in pdf file.I am working with asp.net using C#,kindly give the solution as early as possible

private void ConvertPDF()
{
try
{
string path = Server.MapPath("~/Img/Student Photos//PDFFiles//");
path = path + objbllpreadm.objELLPreAdmission.User_id + ".pdf";

if (File.Exists(path))
{
File.Delete(path);
}

attchmt = objbllpreadm.objELLPreAdmission.User_id + ".pdf";
string filename1 = "";
filename1 = objbllpreadm.objELLPreAdmission.User_id + ".pdf";

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filename1);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

this.Page.RenderControl(hw);
var output = new FileStream(path, FileMode.Create);

StringReader sr = new StringReader(sw.ToString());

iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3, 0f, 10f, 10f, 0f);


HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);

pdfDoc.Open();
htmlparser.Parse(sr);

pdfDoc.Close();
Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception exp)
{
var ErrorMessage = new JavaScriptSerializer().Serialize(exp.Message.ToString());
ShowAlertMessage(ErrorMessage);
}
}


the above method i am using for converting the aspx page to pdf document,the code completely running,no errors throwing,after running the code one pdf file will download which contains 2 pages and one more file will create in "~/Img/Student Photos//PDFFiles//" folder which contains single page...remaining data not coming

推荐答案


这篇关于如何使用itextsharp将aspx页面转换为多页的pdf文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:07