Back to Devexpress

PdfPageFacade.AddFileAttachmentAnnotation(PdfRectangle, PdfFileAttachment) Method

officefileapi-devexpress-dot-pdf-dot-pdfpagefacade-dot-addfileattachmentannotation-x28-devexpress-dot-pdf-dot-pdfrectangle-devexpress-dot-pdf-dot-pdffileattachment-x29.md

latest3.9 KB
Original Source

PdfPageFacade.AddFileAttachmentAnnotation(PdfRectangle, PdfFileAttachment) Method

Adds a file attachment annotation in the specified page rectangle.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public PdfFileAttachmentAnnotationFacade AddFileAttachmentAnnotation(
    PdfRectangle rect,
    PdfFileAttachment file
)
vb
Public Function AddFileAttachmentAnnotation(
    rect As PdfRectangle,
    file As PdfFileAttachment
) As PdfFileAttachmentAnnotationFacade

Parameters

NameTypeDescription
rectPdfRectangle

A page area to add the annotation.

| | file | PdfFileAttachment |

The file associated with this annotation.

|

Returns

TypeDescription
PdfFileAttachmentAnnotationFacade

An object that contains file attachment annotation properties.

|

Remarks

The code sample below creates a file attachment annotation:

csharp
using DevExpress.Pdf;
using System.IO;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    // Access the first page properties
    PdfPageFacade pageFacade = processor.DocumentFacade.Pages[0];

    // Define an annotation area
    PdfRectangle pdfRectangle = new PdfRectangle(684, 152, 704, 172);

    // Specify attachment data
    PdfFileAttachment attachment = new PdfFileAttachment()
    {
        CreationDate = DateTime.Now,
        Description = "This is my attach file.",
        FileName = "MyAttach.txt",
        Data = File.ReadAllBytes("..\\..\\FileToAttach.txt")
    };

    // Create an annotation
    PdfFileAttachmentAnnotationFacade fileAttachmentAnnotation =
       pageFacade.AddFileAttachmentAnnotation(pdfRectangle, attachment);

    // Specify annotation properties
    fileAttachmentAnnotation.Author = "Sabella Jaida";
    fileAttachmentAnnotation.Subject = "File Attachment";

    // Save the result
    processor.SaveDocument("..\\..\\Result.pdf");
}
vb
Imports DevExpress.Pdf
Imports System.IO
'...
Using processor As New PdfDocumentProcessor()
  ' Load a document
  processor.LoadDocument("..\..\Document.pdf")

  ' Access the first page properties
  Dim pageFacade As PdfPageFacade = processor.DocumentFacade.Pages(0)

  ' Define an annotation area
  Dim pdfRectangle As New PdfRectangle(684, 152, 704, 172)

  ' Specify attachment data
  Dim attachment As New PdfFileAttachment() With 
  {
    .CreationDate = Date.Now,
    .Description = "This is my attached file.",
    .FileName = "MyAttach.txt",
    .Data = File.ReadAllBytes("..\..\FileToAttach.txt")
  }

  ' Create an annotation
  Dim fileAttachmentAnnotation As PdfFileAttachmentAnnotationFacade =
     pageFacade.AddFileAttachmentAnnotation(pdfRectangle, attachment)

  ' Specify annotation properties
  fileAttachmentAnnotation.Author = "Sabella Jaida"
  fileAttachmentAnnotation.Subject = "File Attachment"

  ' Save the result
  processor.SaveDocument("..\..\Result.pdf")
End Using

See Also

PdfPageFacade Class

PdfPageFacade Members

DevExpress.Pdf Namespace