Add Attachment in C++
Contents
[
Hide
]
Use PdfContentEditor for this task. The examples below retain the original C++ code and API Reference steps.
Add attachment
Attach the supplied file stream using its filename and a sample description.
- Create PdfContentEditor.
- Bind the PDF input with Facade::BindPdf().
- Attach the file with PdfContentEditor::AddDocumentAttachment().
- Save the resulting PDF with PdfContentEditor::
Save().
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <system/io/file.h>
#include <system/io/file_stream.h>
#include <system/io/path.h>
#include <system/string.h>
namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
void AddAttachment(String inputFile, String attachmentFile, String outputFile)
{
auto editor = MakeObject<PdfContentEditor>();
auto attachmentStream = System::IO::File::OpenRead(attachmentFile);
editor->BindPdf(inputFile);
editor->AddDocumentAttachment(attachmentStream, System::IO::Path::GetFileName(attachmentFile),
u"Sample attachment.");
editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor