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: 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
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");
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
var pdfApi = new PdfApi(AppSecret, AppSid);
using var filePdf = File.OpenRead(LOCAL_FILE_NAME);
await pdfApi.UploadFile(STORAGE_FILE_NAME, filePdf);
using var fileAttach = File.OpenRead(LOCAL_ATTACHMENT_FILE_NAME);
await pdfApi.UploadFile(STORAGE_ATTACHMENT_FILE_NAME, fileAttach);
var response = pdfApi.PostAddDocumentAttachment(STORAGE_FILE_NAME, attachmentInfo);
Console.WriteLine(response.Code);
if (response.Code == 200)
{
pdfApi.DownloadFile(STORAGE_FILE_NAME)
.CopyTo(File.Create(Path.Combine(localFolder, RESULT_FILE_NAME)));
}
}
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for .NET?
- Customers List
- Security