我想使用 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();
}