Notifications
Announcements
No record found.
public static byte[] CreatePdfA3WithAttachment(byte[] pdfContent, byte[] xmlData, Stream iccProfileData) { using (MemoryStream pdfStream = new MemoryStream()) { PdfWriter writer = new PdfWriter(pdfStream); PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_3B, new PdfOutputIntent("Custom ICC Profile", "", "https://www.color.org", "", iccProfileData)); Document document = new Document(pdfDocument); pdfDocument.GetDocumentInfo().SetTitle("PDF/A-3 Document with XML Attachment"); pdfDocument.GetDocumentInfo().SetAuthor("Author Name"); pdfDocument.GetDocumentInfo().SetSubject("PDF/A-3 Document"); pdfDocument.GetDocumentInfo().SetKeywords("PDF/A-3, XML, iText7"); pdfDocument.SetTagged(); pdfDocument.GetCatalog().SetLang(new PdfString("en-US")); pdfDocument.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); using (MemoryStream existingPdfStream = new MemoryStream(pdfContent)) { try { PdfReader pdfReader = new PdfReader(existingPdfStream); PdfDocument existingPdf = new PdfDocument(pdfReader); existingPdf.CopyPagesTo(1, existingPdf.GetNumberOfPages(), pdfDocument); existingPdf.Close(); } catch (Exception ex) { Console.WriteLine("Exception while adding existing content: " + ex.Message); } } using (MemoryStream xmlStream = new MemoryStream(xmlData)) { PdfDictionary fileParameter = new PdfDictionary(); PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec( pdfDocument, xmlStream.ToArray(), "attached.xml", "attached.xml", PdfName.ApplicationXml, fileParameter, PdfName.Data); pdfDocument.AddFileAttachment("attached.xml", fileSpec); PdfArray afArray = new PdfArray(); afArray.Add(fileSpec.GetPdfObject()); pdfDocument.GetCatalog().Put(new PdfName("AF"), afArray); } document.Close(); return pdfStream.ToArray(); } }
Microsoft.Extensions.Logging
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 592 Most Valuable Professional
André Arnaud de Cal... 478 Super User 2025 Season 2
BillurSamdancioglu 305 Most Valuable Professional