且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iTextSharp可以将PDF文档转换为PDF/A吗

更新时间:2023-02-12 22:03:07

On This thread (dated June 2007) Paulo Soares provides code that shows support for PDF/A. Here's the C# code (he also has a Java sample):

private void PdfATest() {
    Document doc = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\\hello_A1-b_cs.pdf", FileMode.Create));
    writer.PDFXConformance = PdfWriter.PDFA1B;
    doc.Open();

    PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
    outi.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
    outi.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
    outi.Put(PdfName.S, PdfName.GTS_PDFA1);

    // get this file here: http://old.nabble.com/attachment/10971467/0/srgb.profile
    ICC_Profile icc = ICC_Profile.GetInstance("c:\\srgb.profile");
    PdfICCBased ib = new PdfICCBased(icc);
    ib.Remove(PdfName.ALTERNATE);
    outi.Put(PdfName.DESTOUTPUTPROFILE, writer.AddToBody(ib).IndirectReference);

    writer.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outi));

    BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\arial.ttf", BaseFont.WINANSI, true);
    Font f = new iTextSharp.text.Font(bf, 12);
    doc.Add(new Paragraph("hello", f));

    writer.CreateXmpMetadata();

    doc.Close();
}

上面的链接包括ICC_Profile文件的下载.

The link above includes a download for the ICC_Profile file.