C# 如何生成A-2 PDF
我正在尝试使用iText 7创建一个A-2 ODF,但遇到以下异常: iText.Pdfa.Pdfa一致性异常:“所有字体必须 嵌入的这一个不是:倍黑体' 如果有人能帮助我,我将不胜感激 我的代码是:C# 如何生成A-2 PDF,c#,pdf,C#,Pdf,我正在尝试使用iText 7创建一个A-2 ODF,但遇到以下异常: iText.Pdfa.Pdfa一致性异常:“所有字体必须 嵌入的这一个不是:倍黑体' 如果有人能帮助我,我将不胜感激 我的代码是: iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter (pdfNewName); ConverterProperties properties = new ConverterProperties (); iText
iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter (pdfNewName);
ConverterProperties properties = new ConverterProperties ();
iText.Pdfa.PdfADocument pdf = new iText.Pdfa.PdfADocument (writer, iText.Kernel.Pdf.PdfAConformanceLevel.PDF_A_2B, new iText.Kernel.Pdf.PdfOutputIntent ("Custom", "", 6-2) ", new FileStream (profile, FileMode.Open)));
iText.Layout.Document document = new iText.Layout.Document (pdf);
iText.Kernel.Font.PdfFont ExternalSource = iText.Kernel.Font.PdfFontFactory.CreateFont (bold, iText.IO.Font.PdfEncodings.WINANSI);
iText.Layout.Element.Paragraph p = new iText.Layout.Element.Paragraph ();
p.SetFont (externalSource);
document.Add (p);
HtmlConverter.ConvertToPdf (htmlString, pdf, properties);
你看过PDF工厂的文档了吗?它的一些方法使用一个参数来指定是否应该嵌入字体。比如这个:
iText.Kernel.Font.PdfFontFactory.CreateRegisteredFont ( String fontName,
String encoding,
bool embedded
)
如果要生成PDF/a文件,必须嵌入所有字体,即使是标准的14种字体,如Times。因此,您必须告诉iText嵌入您希望它用于文本的字体。我已经输入了泰晤士报字体,但仍然得到相同的错误,这是我的代码iText.Kernel.font.PdfFont ExternalSource=iText.Kernel.font.PdfFontFactory.CreateFont(timesRoman,iText.IO.font.PdfEncodings.WINANSI,true);iText.Layout.Element.paragration p=新的iText.Layout.Element.paragration();p、 SetFont(外部源代码);文件.添加(p);HtmlConverter.ConvertToPdf(htmlString,pdf,properties);