private static void TestPdf2PdfA() { string pdfPath = @""; string outputPath = @""; PdfCreator pdfCreator = new PdfCreator(); List <KeyValuePair <string, string> > properties = new List <KeyValuePair <string, string> >(); properties.Add(new KeyValuePair <string, string>("Title", "ETDA Recommendation PDF/A-3U Example")); properties.Add(new KeyValuePair <string, string>("Author", "Author 1")); properties.Add(new KeyValuePair <string, string>("Author", "Author 2")); properties.Add(new KeyValuePair <string, string>("Subject", "Example Document")); properties.Add(new KeyValuePair <string, string>("Keywords", "ETDA Recommendation Basic Level Document")); // use default if not define OutputIntents outputIntents = new OutputIntents(); outputIntents.colorProfilePath = @""; outputIntents.outputConditionIdentifier = "sRGB IEC61966-2.1"; outputIntents.outputCondition = ""; outputIntents.registryName = "http://www.color.org"; outputIntents.info = "sRGB IEC61966-2.1"; byte[] pdfByte = File.ReadAllBytes(pdfPath); byte[] result = pdfCreator.Pdf2PdfA(pdfByte, properties, outputIntents); //byte[] result = pdfCreator.Pdf2PdfA(pdfByte, properties, null); File.WriteAllBytes(outputPath, result); }
private void GenerateEAttachmentDocument(PdfAWriter writer, XmpWriter xmpWriter, EAttactment attachment) { // Use default intent if output intent of this instance was not set if (attachment.outputIntents == null) { //byte[] iccProfile = File.ReadAllBytes("/Resources/sRGB Color Space Profile.icm"); byte[] iccProfile = Properties.Resources.sRGB_Color_Space_Profile; ICC_Profile icc = ICC_Profile.GetInstance(iccProfile); writer.SetOutputIntents("sRGB IEC61966-2.1", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); } else { OutputIntents outputIntents = attachment.outputIntents; byte[] iccProfileByteArray = File.ReadAllBytes(outputIntents.colorProfilePath); ICC_Profile icc = ICC_Profile.GetInstance(iccProfileByteArray); writer.SetOutputIntents(outputIntents.outputConditionIdentifier, outputIntents.outputCondition, outputIntents.registryName, outputIntents.info, icc); } //============= Create Exchange ECertificate ================= // 1 add ContentInformation.xml to document PdfArray attachmentArray = new PdfArray(); writer.ExtraCatalog.Put(new PdfName("AF"), attachmentArray); PdfFileSpecification contentSpec = this.EmbeddedAttachment(attachment.contentInformationXMLPath, attachment.attachmentName, attachment.attachmentMIME, new PdfName(attachment.attachmentType), writer, attachment.attachmentDescription); attachmentArray.Add(contentSpec.Reference); foreach (var item in attachment.fileAttachments) { contentSpec = this.EmbeddedAttachment(item.attachmentPath, item.attachmentName, item.attachmentMIME, new PdfName(item.attachmentType), writer, item.attachmentDescription); attachmentArray.Add(contentSpec.Reference); } // 2 add Electronic Document XMP Metadata ElectronicDocumentSchema ed = ElectronicDocumentSchema.generateED(attachment.attachmentName, attachment.documentVersion, attachment.documentID, attachment.documentOID); xmpWriter.AddRdfDescription(ed); string pdfaSchema = Properties.Resources.EDocument_PDFAExtensionSchema; // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(pdfaSchema); //byte[] byteArray = Encoding.ASCII.GetBytes(contents); MemoryStream stream = new MemoryStream(byteArray); IXmpMeta edPDFAextension = XmpMetaFactory.Parse(stream); IXmpMeta originalXMP = xmpWriter.XmpMeta; XmpUtils.AppendProperties(edPDFAextension, originalXMP, true, true); }
private static void TestPdf2PdfAWithAttachment() { string pdfPath = @""; string outputPath = @""; PdfCreator pdfCreator = new PdfCreator(); List <KeyValuePair <string, string> > properties = new List <KeyValuePair <string, string> >(); properties.Add(new KeyValuePair <string, string>("Title", "ETDA Recommendation PDF/A-3U Example")); properties.Add(new KeyValuePair <string, string>("Author", "Author 1")); properties.Add(new KeyValuePair <string, string>("Author", "Author 2")); properties.Add(new KeyValuePair <string, string>("Subject", "Example Document")); properties.Add(new KeyValuePair <string, string>("Keywords", "ETDA Recommendation Basic Level Document")); EAttactment eAttach = new EAttactment(); //EAttactment eAttach = new EAttactment("ContentInformation.xml", "resource/ContentInformation.xml", "Text/XML",EAttactment.ALTERNATIVE, "Document Content in XML format"); eAttach.attachmentName = "ContentInformation.xml"; eAttach.contentInformationXMLPath = "resource/ContentInformation.xml"; eAttach.attachmentMIME = "Text/XML"; eAttach.attachmentType = EAttactment.ALTERNATIVE; eAttach.attachmentDescription = "Document Content in XML format"; eAttach.documentID = "C# example 01/2559"; eAttach.documentOID = "2.16.764.1.4.100.0.0.0.0"; eAttach.documentVersion = "1.0"; FileAttachment fileAttach = new FileAttachment(); fileAttach.attachmentName = @"FileAttach.docx"; fileAttach.attachmentPath = @"D:/specification.docx"; fileAttach.attachmentMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; fileAttach.attachmentType = EAttactment.SOURCE; fileAttach.attachmentDescription = "Specification Document"; eAttach.fileAttachments = new List <FileAttachment>(); eAttach.fileAttachments.Add(fileAttach); // use default if not define OutputIntents outputIntents = new OutputIntents(); outputIntents.colorProfilePath = @""; outputIntents.outputConditionIdentifier = "sRGB IEC61966-2.1"; outputIntents.outputCondition = ""; outputIntents.registryName = "http://www.color.org"; outputIntents.info = "sRGB IEC61966-2.1"; eAttach.outputIntents = outputIntents; byte[] pdfByte = File.ReadAllBytes(pdfPath); byte[] result = pdfCreator.Pdf2PdfA(pdfByte, properties, eAttach); File.WriteAllBytes(outputPath, result); }
private void generatePDFA3Document(PdfAWriter writer, OutputIntents outputIntents) { // Use default intent if output intent of this instance was not set if (outputIntents == null) { //byte[] iccProfile = File.ReadAllBytes("/Resources/sRGB Color Space Profile.icm"); byte[] iccProfileByteArray = Properties.Resources.sRGB_Color_Space_Profile; ICC_Profile icc = ICC_Profile.GetInstance(iccProfileByteArray); writer.SetOutputIntents("sRGB IEC61966-2.1", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); } else { byte[] iccProfileByteArray = File.ReadAllBytes(outputIntents.colorProfilePath); ICC_Profile icc = ICC_Profile.GetInstance(iccProfileByteArray); writer.SetOutputIntents(outputIntents.outputConditionIdentifier, outputIntents.outputCondition, outputIntents.registryName, outputIntents.info, icc); } }
public byte[] Pdf2PdfA(byte[] pdf, List <KeyValuePair <string, string> > properties, OutputIntents outputIntents) { PdfReader document = new PdfReader(pdf); MemoryStream stream = new MemoryStream(); Document pdfADocument = new Document(); PdfAWriter writer = this.CreatePDFAInstance(pdfADocument, document, stream); writer.CreateXmpMetadata(); XmpWriter xmpWriter = writer.XmpWriter; properties.ForEach(delegate(KeyValuePair <string, string> keyValuePairs) { xmpWriter.AddDocInfoProperty(keyValuePairs.Key, keyValuePairs.Value); }); generatePDFA3Document(writer, outputIntents); pdfADocument.Close(); document.Close(); return(stream.ToArray()); }