使用itextsharp创建pdf / A-3 [英] Create pdf/A-3 using itextsharp
本文介绍了使用itextsharp创建pdf / A-3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能帮我创建一个带有itextsharp的嵌入式xml文件的pdf / A-3。我正在尝试创建,但得到错误所有字体必须嵌入。这不是:Helvetica
我在这里提供的示例代码
Can you help me to create a pdf/A-3 with an embedded xml file with itextsharp . I am trying to create but got error "All the fonts must be embedded. This one isn't: Helvetica"
The sample code I have provided here
using iTextSharp.text.pdf;
using iTextSharp.text;
private void createPdfA()
{
Document document = new Document();
// Create PdfAWriter with PdfAConformanceLevel.PDF_A_3B option if you
// want to get a PDF/A-3b compliant document.
PdfAWriter writer = PdfAWriter.GetInstance(document,
new FileStream("./xmp_metadata.pdf",FileMode.Create),
PdfAConformanceLevel.PDF_A_3B);
// Create XMP metadata. It's a PDF/A requirement.
writer.CreateXmpMetadata();
document.Open();
// Set output intent. PDF/A requirement.
ICC_Profile icc = ICC_Profile
.GetInstance(
"./sRGB Color Space Profile.icm");
writer.SetOutputIntents("Custom", "", "http://www.color.org",
"sRGB IEC61966-2.1", icc);
// All fonts shall be embedded. PDF/A requirement.
var fonts=FontFactory.GetFont(
"./FreeSansBold.ttf",
BaseFont.WINANSI, BaseFont.EMBEDDED, 10);
Font normal9 = FontFactory.GetFont(
"./FreeSans.ttf",
BaseFont.WINANSI, BaseFont.EMBEDDED, 9);
Font bold9 = FontFactory.GetFont(
"./FreeSansBold.ttf",
BaseFont.WINANSI, BaseFont.EMBEDDED, 9);
Font normal8 = FontFactory.GetFont(
"./FreeSans.ttf",
BaseFont.WINANSI, BaseFont.EMBEDDED, 8);
// Creating PDF/A-3 compliant attachment.
PdfDictionary parameters = new PdfDictionary();
parameters.Put(PdfName.MODDATE, new PdfDate());
PdfFileSpecification fileSpec = PdfFileSpecification.FileEmbedded(
writer, "./invoice.xml",
"invoice.xml", null, "application/xml", parameters, 0);
fileSpec.Put(new PdfName("AFRelationship"), new PdfName("Data"));
writer.AddFileAttachment("invoice.xml", fileSpec);
PdfArray array = new PdfArray();
array.Add(fileSpec.Reference);
writer.ExtraCatalog.Put(new PdfName("AF"), array);
// From here on we can add content to the PDF just like we would do for
// a regular PDF.
// Building header.
document.Add(new Paragraph("Invoice number: " + 1));
// document.Add(new Paragraph("\n", normal8));
document.Add(new Paragraph("Dear " +"NAMEInvoice"));
document.Add(new Paragraph(
"Thank you "
));
document.Add(new Paragraph("\n"));
document.Close();
writer.Close();
}
推荐答案
以下文章可能会对您有所帮助。
1. 带有嵌入字体的ITextSharp PDF / A [< a href =http://danielbergsten.wordpress.com/2010/06/22/itextsharp-pdfa-with-embedded-font/target =_ blanktitle =New Window> ^ ]
2. iTextSharp可以将PDF文档转换为PDF / A [ ^ ]
3. iTextSharp - 使用字体 [ ^ ]
The below articles might help you.
1. ITextSharp PDF/A with embedded font[^]
2. Can iTextSharp convert PDF document to PDF/A[^]
3. iTextSharp - Working with Fonts[^]
这篇关于使用itextsharp创建pdf / A-3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文