我们无法更改从以下代码生成的 pdf 的字体大小有人可以帮助我们吗?
我们想在更改字体大小后将该 html 文件转换为 pdf。
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
protected void ConvertToPDFNow()
{
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
print.RenderControl(w);
string htmWrite = sw.GetStringBuilder().ToString();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
htmWrite = Regex.Replace(htmWrite, "</?(a|A).*?>", "");
htmWrite = htmWrite.Replace("\r\n", "");
StringReader reader = new StringReader(htmWrite);
Document doc = new Document(PageSize.A4);
//Creating Document of A4 Size
HTMLWorker parser = new HTMLWorker(doc);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
try
{
//rendering Html File
parser.Parse(reader);
}
catch (Exception ex)
{
}
finally
{
doc.Close();
}
}