PDF for .NET
添付

PDF lets you add different types of attachments to your documents including sample code, and spreadsheets with detailed information that can clutter the document or multimedia items like videos, audios, or images and so on. The attachments are displayed in a Pdf document with an attachment icon, a paper clip icon. Right-clicking the icon provides you options to save or access the attachment as a file.

The following image showcases files attached to a Pdf document.

You can use AddAttachment method of the C1PdfDocument class to attach a file in your Pdf document. The AddAttachment method has various overloads which can be used to specify the files you want to attach, what area of the page should contain the attachments, and optionally, the appearance of the attachment.

To add an attachment to Pdf document, use the following code. In this example, we add some files located at the bin directory of the project folder as attachments to the Pdf document.

C#
コードのコピー
// いくつかのファイルを添付します
string path = "files";
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
    float width = rect.Width;
    rect.Width = rect.Height;
    pdf.FillRectangle(Brushes.Gray, rect);
    pdf.AddAttachment(file, rect);
    rect.Width = width;
    rect.X += rect.Height;
    pdf.DrawString(Path.GetFileName(file), font, Brushes.Black, rect);
    rect.X -= rect.Height;
    rect.Y += 2 * rect.Height;
}