iText 设置一致性级别
iText set conformance level
目前我正在尝试使用 iText for C# 创建符合级别 A-1a 的 PDF 文件。这是我目前所拥有的:
var exportFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var exportFile = System.IO.Path.Combine(exportFolder, "Test.pdf");
var writer = new PdfWriter(exportFile);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
document.Add(new Paragraph("Hello World! Tom"));
document.Close();
如何为此设置一致性级别?
编辑
我在他们的文档中找到了这个:
https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/chapter-7-creating-pdfua-and-pdfa-documents
但是我没有得到我必须在第三行代码中替换 INTENT 的内容。
有人能给我一个只有一行 Hello World 的完整示例吗?它不一定必须是 iText。我对其他工具持开放态度。
尝试替换这一行
var pdf = new PdfDocument(writer);
有了这个
PdfADocument pdf = new PdfADocument(new PdfWriter(exportFile), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read
)));
Document document = new Document(pdf);
// Etc...
除此之外,我的建议始终是声明实例化的 class 而不是保留泛型(使用 var),正如您从我的示例代码中看到的那样。
希望这能奏效!
干杯
第 1 步:
下载颜色配置文件。
您可以使用 iText 示例中提供的那个。 http://gitlab.itextsupport.com/itext7/samples/blob/develop/publications/jumpstart/src/main/resources/color/sRGB_CS_profile.icm
第 2 步:
//Initialize PDFA document with output intent
PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream("sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read
)));
Document document = new Document(pdf);
//Fonts need to be embedded
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("The quick brown "));
iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX));
p.Add(foxImage);
p.Add(" jumps over the lazy ");
iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
p.Add(dogImage);
document.Add(p);
document.Close();
目前我正在尝试使用 iText for C# 创建符合级别 A-1a 的 PDF 文件。这是我目前所拥有的:
var exportFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var exportFile = System.IO.Path.Combine(exportFolder, "Test.pdf");
var writer = new PdfWriter(exportFile);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
document.Add(new Paragraph("Hello World! Tom"));
document.Close();
如何为此设置一致性级别?
编辑
我在他们的文档中找到了这个: https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/chapter-7-creating-pdfua-and-pdfa-documents
但是我没有得到我必须在第三行代码中替换 INTENT 的内容。 有人能给我一个只有一行 Hello World 的完整示例吗?它不一定必须是 iText。我对其他工具持开放态度。
尝试替换这一行
var pdf = new PdfDocument(writer);
有了这个
PdfADocument pdf = new PdfADocument(new PdfWriter(exportFile), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read
)));
Document document = new Document(pdf);
// Etc...
除此之外,我的建议始终是声明实例化的 class 而不是保留泛型(使用 var),正如您从我的示例代码中看到的那样。
希望这能奏效! 干杯
第 1 步:
下载颜色配置文件。
您可以使用 iText 示例中提供的那个。 http://gitlab.itextsupport.com/itext7/samples/blob/develop/publications/jumpstart/src/main/resources/color/sRGB_CS_profile.icm
第 2 步:
//Initialize PDFA document with output intent
PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent
("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream("sRGB_CS_profile.icm", FileMode.Open, FileAccess.Read
)));
Document document = new Document(pdf);
//Fonts need to be embedded
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("The quick brown "));
iText.Layout.Element.Image foxImage = new Image(ImageDataFactory.Create(FOX));
p.Add(foxImage);
p.Add(" jumps over the lazy ");
iText.Layout.Element.Image dogImage = new iText.Layout.Element.Image(ImageDataFactory.Create(DOG));
p.Add(dogImage);
document.Add(p);
document.Close();