如何使用PDF4NET控件创建PDFA格式的PDF文件

作者:控件中国网   出处:控件中国网   2015-09-09 14:41:03   阅读:12

PDF4NET是一款可以用于PDF文件的创建、编辑、填充、合并、分割、和加密等的.NET控件,可以快速帮助开发人员创建PDF文档处理应用程序,大量节约开发项目的周期,降低项目开发的风险和成本,随着PDFA格式文件的流行和使用,在很多场合需要使用到PDFA格式,那么这篇文章主要介绍如何使用PDF4NET创建PDFA格式的PDF文件,具体可以参考下面的部分代码:

 public class PDFA

    {

        static void Main(string[] args)

        {

            PDFDocument doc = new PDFDocument();

            doc.SerialNumber = "serial number here";

 

            // Read the ICC profile from disk.

            FileStream fs = new FileStream("..\\SupportFiles\\rgb.icc", FileMode.Open, FileAccess.Read);

            byte[] profileData = new byte[fs.Length];

            fs.Read(profileData, 0, profileData.Length);

            fs.Close();

 

            // Create a RGB output intent and attach it to the document.

            PDFICCColorSpace icc = new PDFICCColorSpace();

            icc.ProfileData = profileData;

            PDFOutputIntent oi = new PDFOutputIntent();

            oi.Type = PDFOutputIntentType.PDFA1;

            oi.Info = "sRGB IEC61966-2.1";

            oi.OutputConditionIdentifier = "Custom";

            oi.DestinationOutputProfile = icc;

 

            doc.OutputIntents = new PDFOutputIntentCollection();

            doc.OutputIntents.Add(oi);

 

            // Set the document information and metadata.

            PDFDocumentInformation di = new PDFDocumentInformation();

            di.Author = "O2 Solutions";

            di.Producer = "PDF4NET";

            di.Keywords = "pdf";

            di.Subject = "PDF/A-1b Demo Document created with PDF4NET";

            di.Title = "PDF4NET Demo";

            di.Creator = "PDF4NET Demo";

            doc.DocumentInformation = di;

            doc.Metadata = new PDFXMPMetadata();

 

            PDFPage page = doc.AddPage();

 

            // Use an embedded TrueType font to draw the text.

            TrueTypeFont ttf = new TrueTypeFont("..\\SupportFiles\\Verdana.ttf", 96, true, true);

            PDFBrush yellowBrush = new PDFBrush(new PDFRgbColor(255, 255, 0));

            PDFPen greenPen = new PDFPen(new PDFRgbColor(64, 192, 0), 4);

            page.Canvas.DrawText("PDF/A-1b Demo",

                ttf, greenPen, yellowBrush, page.Width / 2, page.Height / 2, 60, PDFTextAlign.MiddleCenter);

 

            // Save the document in PDF/A-1b format.

            PDFDocumentSaveOptions dso = new PDFDocumentSaveOptions();

            dso.SaveFormat = PDFDocumentSaveFormat.PDFA1b;

            doc.Save("Sample_PDFA.pdf", dso);

        }

    }

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat