我想使用iTextsharp从HTML创建PDF / A,但是很难创建经过验证的PDF /。这是我用来测试功能的代码。什么需要改变才能得到我想要的东西?
static void Main(string[] args)
{
//create stylesheet (used to change font from default Helvetica in order to embed font in PDF/A)
var styles = new StyleSheet();
var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\verdana.ttf";
FontFactory.Register(fontPath);
styles.LoadTagStyle("body", "face", "Verdana");
var pdFdocument = new Document(PageSize.A4);
const string strPdFpath = @"MyPDF.pdf-PDFX1A2001";
var sr = new StringReader("<html><head></head><body><h1>Dette er en HTML-fil</h1><p>Dette er litt tekst i html-fila</p><br /><p>Dette er enda ett avsnitt. iTextSharp ser ut til å fungere greit...</p></body></html>");
var htmlParser = new HTMLWorker(pdFdocument, null, styles);
PdfWriter writer = PdfWriter.GetInstance(pdFdocument, new FileStream(strPdFpath, FileMode.OpenOrCreate));
writer.PDFXConformance = PdfWriter.PDFX1A2001;
pdFdocument.Open();
htmlParser.Parse(sr);
pdFdocument.Close();
}