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.
Congratulations to our community stars!
Expanding mentorship, skilling, and AI innovation
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 528 Most Valuable Professional
André Arnaud de Cal... 424 Super User 2026 Season 2
CU10121822-0 374