我有一个项目可以将HTML页面导出为PDF
HTML页面有一个包含4列和20行的表,一旦在PDF上导出,这些行就没有对齐,我试图在HMTL中修复,设置宽度但没有结果
这里有一个示例项目可供下载,并且易于尝试
http://www.suale.it/provaAPP/WindowsFormsApp1.zip
这里是HTML页面
http://www.suale.it/provaAPP/TemplateVL.htm
结果在这里
http://www.suale.it/provaAPP/PDF.jpg
怎么了?
这里我用来转换的代码
private void button1_Click(object sender, EventArgs e)
{
StyleSheet css = new StyleSheet();
FontFactory.Register(Application.StartupPath + @"\cour.ttf", "CourierN");
string outputFile = Application.StartupPath + @"\file.pdf";
string fileHTML = Application.StartupPath + @"\TemplateVL.htm";
string HTML = File.ReadAllText(fileHTML);
string filepath = outputFile;
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filepath, FileMode.Create));
HTML = HTML.Replace("[", "");
HTML = HTML.Replace("]", "");
HTML = HTML.Replace("@", "");
document.Open();
StringReader sr = new StringReader(HTML);
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, sr);
document.Close();
byte[] Bites = creaPDF(Application.StartupPath+ @"\file.css",HTML );
File.WriteAllBytes(outputFile, Bites);
var fol = new ProcessStartInfo(outputFile);
fol.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(fol);
}