使用itextsharp进行html转pdf时生成的pdf里不显示checkbox复选框,请问一下这个问题该怎么去解决?
这个是转换的代码,保存到根目录里的文件夹
public static string ConvertHtmlToPdf(string html, string path, int? NotA4 = null)
{
string url = string.Empty;
byte[] data = Encoding.UTF8.GetBytes(html.ToString()); //字串转成byte[]
MemoryStream outputStream = new MemoryStream();//要把PDF写到哪个串流
MemoryStream msInput = new MemoryStream(data);
Document doc;
//参数为空,默认A4 竖向,否则横向
if (NotA4 != null)
doc = new Document(new RectangleReadOnly(PageSize.A4.Height, PageSize.A4.Width)
{
});
else
doc = new Document();
doc.SetMargins(20f, 20f, 20f, 0f);
//要写PDF的文件,建构子没填的话预设直式A4
PdfWriter writer = PdfWriter.GetInstance(doc, outputStream);
//指定文件预设开档时的缩放为100%
PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 1f);
//开启Document文件
doc.Open();
////使用XMLWorkerHelper把Html parse到PDF档里
XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msInput, Encoding.UTF8);
PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);
writer.SetOpenAction(action);
doc.Close();
msInput.Close();
outputStream.Close();
if (outputStream.ToArray().Length > 0)
{
var array = outputStream.ToArray();
FileStream fs = new FileStream(path, FileMode.Create);
//将byte数组写入文件中
fs.Write(array, 0, array.Length);
fs.Close();
url = path;
}
return url;
}