add or remove attachments in pdf c++

PDF has become a massively used file format because of its cross-platform support. You can create a PDF on the Windows platform, for example, and then transfer it to the Mac without any compatibility or formatting issues. One of the powerful features that PDF supports is adding attachments. You can embed other documents into a PDF file just like the email attachments. In this article, you are going to learn how to deal with PDF attachments programmatically. More specifically, you will come to know how to get, add, and remove attachments in PDF files using C++.

C++ API for PDF Attachments - Free Download

In order to work with PDF attachments seamlessly, you can leverage the capabilities of Aspose.PDF for C++. The API lets you add, remove, or access the PDF attachments within a few lines of code. You can download the API’s package or get it installed using NuGet.

PM> Install-Package Aspose.PDF.Cpp

Get PDF Attachment Information using C++

First of all, let’s have a look at how to access the attachments’ information from a PDF document. For this, you can follow the below steps.

The following code sample shows how to get PDF attachment’s information using C++.

Add an Attachment to PDF in C++

Now, let’s check out how to add an attachment to the PDF using Aspose.PDF for C++. The attachment could be any file such as DOCX, TXT, and etc. The following are the steps for adding a TXT file to PDF as an attachment.

The following code sample shows how to add an attachment to a PDF using C++.

Remove an Attachment from PDF in C++

You can also remove the selected or all the attachments from the PDF using Aspose.PDF for C++. The following are the steps to do so.

The following code sample shows how to remove attachments from a PDF using C++.

Conclusion

In this article, you have learned how to manipulate attachments in PDF files using C++. The code samples have demonstrated how to access, add and remove the attachments from PDF files programmatically. You can learn more about the C++ PDF API using the documentation.

See Also