Add Attachments
IronPDF supports adding and removing attachments to your PDF documents.
using IronPdf; using System.Collections.Generic; using System.Linq; // Instantiate the Renderer and create PdfDocument from HTML var renderer = new ChromePdfRenderer(); var myPdf = renderer.RenderHtmlFileAsPdf("my-content.html"); // Load your own attachment List<byte[]> exampleAttachments = new List<byte[]>(); byte[] attachment = exampleAttachments.First(); // Here we can add an attachment with a name and a byte[] var attachment1 = myPdf.Attachments.AddAttachment("attachment_1", attachment); // And here is an example of removing an attachment myPdf.Attachments.RemoveAttachment(attachment1); myPdf.SaveAs("my-content.pdf");
Imports IronPdf Imports System.Collections.Generic Imports System.Linq ' Instantiate the Renderer and create PdfDocument from HTML Private renderer = New ChromePdfRenderer() Private myPdf = renderer.RenderHtmlFileAsPdf("my-content.html") ' Load your own attachment Private exampleAttachments As New List(Of Byte())() Private attachment() As Byte = exampleAttachments.First() ' Here we can add an attachment with a name and a byte[] Private attachment1 = myPdf.Attachments.AddAttachment("attachment_1", attachment) ' And here is an example of removing an attachment myPdf.Attachments.RemoveAttachment(attachment1) myPdf.SaveAs("my-content.pdf")
Install-Package IronPdf