The sample source code below will teach you how to add file attachment to PDF in VB.NET. ByteScout PDF SDK is the library for pdf documents generation, modification and updates. Can also generate and fill PDF forms. Provides support for text (fonts, style, size, font family), layers, pdf form fields, vector and raster drawings and you can use it to add file attachment to PDF with VB.NET.
Fast application programming interfaces of ByteScout PDF SDK for VB.NET plus the instruction and the code below will help you quickly learn how to add file attachment to PDF. Follow the instructions from the scratch to work and copy the VB.NET code. This basic programming language sample code for VB.NET will do the whole work for you to add file attachment to PDF.
ByteScout free trial version is available for download from our website. It includes all these programming tutorials along with source code samples.
Imports Bytescout.PDF ''' <summary> ''' This example demonstrates how to attach a file to PDF document. ''' </summary> Class Program Shared Sub Main() ' Create new document Dim pdfDocument = New Document() pdfDocument.RegistrationName = "demo" pdfDocument.RegistrationKey = "demo" ' Add page Dim page = New Page(PaperFormat.A4) pdfDocument.Pages.Add(page) ' Attach file Dim fileAttachment = New FileAttachmentAnnotation("sample_attachment.txt", 20, 20, 20, 20) fileAttachment.Icon = FileAttachmentAnnotationIcon.Paperclip page.Annotations.Add(fileAttachment) ' Instruct PDF viewer application to show attachments pane on startup pdfDocument.PageMode = PageMode.Attachment ' Save document to file pdfDocument.Save("result.pdf") ' Cleanup pdfDocument.Dispose() ' Open document in default PDF viewer app Process.Start("result.pdf") End Sub End Class
sample_attachment.txt 1234567890 abcdefghijklmnopqrstuvwxyz