PNG
JPG
BMP
TIFF
PDF
Add attachments to PDF in .NET SDK
API for adding attachments in PDF documents with Aspose.PDF Cloud .NET SDK
Get StartedHow to append attachments in PDF documents using C# Cloud API
For adding attachments into PDF documents, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.
Command
PM> Install-Package Aspose.Pdf-Cloud
Steps to add attachments using .NET SDK
A basic adding attachments programmatically with Aspose.PDF Cloud .NET SDK APIs can be done with just few lines of code.
- Create an AttachmentInfo object
- Upload the files to cloud storage
- Add the attachment to the PDF
- Check the response and save the updated PDF
System Requirements
Aspose.PDF Cloud .NET developers can easily extract, and append attachments in PDF documents. Developers need just a few lines of code.
- .NET Framework 2.0 or later
- JSON.NET
This sample code shows adding attachments of PDF document using C#
public static void AddAttachment()
{
var STORAGE_FILE_NAME = "sample_attachment.pdf";
var STORAGE_ATTACHMENT_FILE_NAME = "file_example_MP3_700KB.mp3";
var LOCAL_FILE_NAME = @"C:\Samples\Attachments\sample_attachment.pdf";
var LOCAL_ATTACHMENT_FILE_NAME = @"C:\Samples\Attachments\file_example_MP3_700KB.mp3";
var RESULT_FILE_NAME = @"C:\Samples\Attachments\sample_attachment_new.pdf";
var attachmentInfo = new AttachmentInfo(
STORAGE_ATTACHMENT_FILE_NAME,
"Sample attachment",
Path.GetFileName(LOCAL_ATTACHMENT_FILE_NAME),
"audio/mpeg");
PdfApi.UploadFile(STORAGE_FILE_NAME, File.OpenRead(LOCAL_FILE_NAME));
PdfApi.UploadFile(STORAGE_ATTACHMENT_FILE_NAME, File.OpenRead(LOCAL_ATTACHMENT_FILE_NAME));
var response = PdfApi.PostAddDocumentAttachment(STORAGE_FILE_NAME, attachmentInfo);
Console.WriteLine(response.Code);
if (response.Code == 200)
{
PdfApi.DownloadFile(STORAGE_FILE_NAME)
.CopyTo(File.OpenWrite(RESULT_FILE_NAME));
}
}