Add Line Annotation in C++

Use PdfContentEditor for this task. The examples below retain the original C++ code and API Reference steps.

Add line annotation

Create a red line annotation on page 1 with the specified endpoints, border, and line-ending settings.

  1. Create PdfContentEditor.
  2. Bind the PDF input with Facade::BindPdf().
  3. Create the line annotation with PdfContentEditor::CreateLine().
  4. Save the resulting PDF with PdfContentEditor::Save().
#include <Aspose.PDF.Cpp/Color.h>
#include <Aspose.PDF.Cpp/Facades/PdfContentEditor.h>
#include <drawing/color.h>
#include <drawing/rectangle.h>
#include <system/array.h>
#include <system/string.h>

namespace Facades::Examples::PDF_ContentEditor
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;
using Rectangle = System::Drawing::Rectangle;
using DrawingColor = System::Drawing::Color;

void AddLineAnnotation(String inputFile, String outputFile)
{
    auto editor = MakeObject<PdfContentEditor>();

    editor->BindPdf(inputFile);
    editor->CreateLine(Rectangle(100, 100, 200, 200), u"This is line annotation", 100, 100, 200, 200, 1, 1,
                       DrawingColor::get_Red(), u"Solid", MakeArray<int32_t>({3, 2}), MakeArray<String>({u"Square"}));
    editor->Save(outputFile);
}
} // namespace Facades::Examples::PDF_ContentEditor