This article guides on how to attach image to PDF using C# REST API. You will learn how to attach pictures to PDF using C# REST Interface with the help of a Dotnet-based Cloud SDK. Various types of files will be discussed for adding them to a PDF as an attachment with appropriate settings.
Prerequisite
- Create an account API credentials to attach a file to a PDF
- Download Aspose.PDF Cloud SDK for Dotnet for attaching images and other files to a PDF
- Setup a C# project with the above SDK
Steps to Attach Photo to PDF using C# REST API
- Create an instance of the PdfApi by providing your credentials
- Define the input PDF file, attachment file, and output file name
- Read the source PDF file into the memory stream and upload to the Cloud storage
- Upload the attachment file to the Cloud storage
- Create an instance of the AttachmentInfo and set its parameters
- Add an attachment to the PDF using the PostAddDocumentAttachment method
- Check if the operation is successful or not
- Download the updated PDF file after attaching a file to it
These steps summarize how to attach photo in PDF using C# RESTful Service. Upload the source PDF file and the attachment file to the Cloud storage and create an instance of the AttachmentInfo object. Finally, call the PostAddDocumentAttachment() method by passing the above attachment info object to attach it to the PDF.
Code to Attach Picture to PDF using C# Low Code API
This sample code demonstrates the process to attach photo in PDF using C# REST Interface. Note that it is better to create the AttachmentInfo object by passing all the necessary arguments in the constructor. Set the appropriate Mime Type for the attachment for opening it in the respective application, such as application/pdf, text/plain, text/html, image/png, image/jpeg, to list a few.
This article has taught us how to add files as attachments to a PDF file. To insert comments in a PDF file, refer to the article Insert comment in PDF using C# REST API.