Manage Presentation Ink Objects in PHP

Introduction

PowerPoint provides an ink feature that allows you to draw freeform strokes. Ink can be used to highlight other objects, show connections and processes, and draw attention to specific items on a slide.

Aspose.Slides provides the types needed to work with ink objects. For example, the Ink class represents an ink object on a slide.

Differences between Regular Objects and Ink Objects

Objects on a PowerPoint slide are typically represented by Shape objects. In its simplest form, a shape is a container that defines the area of the object itself (its frame) along with properties such as the container size, shape, and background. For more information, see Shape Layout Format.

However, when PowerPoint handles an ink object, it ignores all properties of the object frame (container) except its size. The size of the container area is determined by the standard Shape.getWidth and Shape.getHeight methods:

ink_powerpoint1

Ink Traces

An ink trace is a basic element used to record the trajectory of a pen as a user writes digital ink. A trace stores a sequence of connected points.

The simplest form of encoding specifies the X and Y coordinates of each sample point. When all connected points are rendered, they produce an image like this:

ink_powerpoint2

Brush Properties for Drawing

A brush is used to draw lines that connect the points of an ink trace. The brush has its own color and size, represented by the InkBrush.getColor and InkBrush.getSize methods.

Set Ink Brush Color

This PHP code shows how to set the color of an ink brush:

$presentation = new Presentation("pres.pptx");
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $ink = $slide->getShapes()->get_Item(0);
    $brush = $ink->getTraces()[0]->getBrush();
    $brush->setColor(java("java.awt.Color")->RED);
} finally {
    $presentation->dispose();
}

Set Ink Brush Size

This PHP code shows how to set the size of an ink brush:

$presentation = new Presentation("pres.pptx");
try {
    $slide = $presentation->getSlides()->get_Item(0);
    $ink = $slide->getShapes()->get_Item(0);
    $brush = $ink->getTraces()[0]->getBrush();
    $brushSize = new Java("java.awt.Dimension", 5, 10);
    $brush->setSize($brushSize);
} finally {
    $presentation->dispose();
}

Generally, a brush’s width and height do not match, so PowerPoint does not display the brush size (the corresponding data section is grayed out). When the brush width and height match, PowerPoint displays its size this way:

ink_powerpoint3

For clarity, let’s increase the height of the ink object and review the important dimensions:

ink_powerpoint4

The container (frame) does not account for the size of the brushes—it always assumes that the line thickness is zero (see the previous image).

Therefore, to determine the visible area of the entire ink object, the brush size of its traces must be taken into account. Here, the target object (the handwritten text trace) has been scaled to the size of the container (frame). When the size of the container changes, the brush size remains constant, and vice versa.

ink_powerpoint5

PowerPoint uses similar behavior for text objects:

ink_powerpoint6

Control Ink Appearance During Export and Rendering

Aspose.Slides provides the InkOptions class to control how ink objects appear in exported or rendered output. You can use its properties to hide ink completely or change how ink brush mask operations are interpreted.

Ink options are available through the export or rendering options for several output types:

Output Ink options property
PDF PdfOptions.getInkOptions
HTML HtmlOptions.getInkOptions
SVG SVGOptions.getInkOptions
TIFF TiffOptions.getInkOptions
Slide image RenderingOptions.getInkOptions

The following InkOptions methods expose the same two settings:

Hide Ink Objects in PDF Output

By default, ink objects remain visible during export. To create a clean output without handwritten annotations or other ink content, call InkOptions.setHideInk with true.

The following PHP example exports a presentation to PDF while hiding all ink objects:

$presentation = new Presentation("presentation.pptx");
try {
    $pdfOptions = new PdfOptions();
    $pdfOptions->getInkOptions()->setHideInk(true);

    $presentation->save("presentation_without_ink.pdf", SaveFormat::Pdf, $pdfOptions);
} finally {
    $presentation->dispose();
}

Hide Ink Objects When Rendering a Slide as an Image

To hide ink objects when rendering slides as bitmap images, configure RenderingOptions.getInkOptions and pass the rendering options to Slide.getImage.

The following PHP example renders the first slide as a PNG image without ink objects:

$presentation = new Presentation("presentation.pptx");
try {
    $renderingOptions = new RenderingOptions();
    $renderingOptions->getInkOptions()->setHideInk(true);

    $slide = $presentation->getSlides()->get_Item(0);
    $image = $slide->getImage($renderingOptions);
    try {
        $image->save("slide_without_ink.png", ImageFormat::Png);
    } finally {
        $image->dispose();
    }
} finally {
    $presentation->dispose();
}

Control Ink Mask Rendering

The InkOptions.getInterpretMaskOpAsOpacity setting controls how mask operations are interpreted when rendering ink brushes. The default value is true, which uses opacity. To use the ROP operation instead, call InkOptions.setInterpretMaskOpAsOpacity with false.

The following PHP example exports a slide to SVG and uses ROP-based rendering for ink mask operations:

$presentation = new Presentation("presentation.pptx");
try {
    $svgOptions = new SVGOptions();
    $svgOptions->getInkOptions()->setInterpretMaskOpAsOpacity(false);

    $outputStream = new Java("java.io.FileOutputStream", "slide.svg");
    try {
        $slide = $presentation->getSlides()->get_Item(0);
        $slide->writeAsSvg($outputStream, $svgOptions);
    } finally {
        $outputStream->close();
    }
} finally {
    $presentation->dispose();
}

The same setting can be applied through TiffOptions.getInkOptions when exporting a presentation or rendering a slide to TIFF.

Choose Whether to Hide or Preserve Ink

When you need a clean version of an annotated presentation for distribution without review marks, call InkOptions.setHideInk with true during export.

Leave InkOptions.getHideInk at its default value of false when ink annotations are part of the intended content, such as review comments, handwritten notes, highlights, or drawings that should remain visible in the exported result. This allows applications to generate separate review and final outputs from the same presentation without modifying the source ink objects.

FAQ

Can I change the color or size of an existing ink stroke?

Yes. Get the trace from Ink.getTraces, then change its InkTrace.getBrush. Call InkBrush.setColor or InkBrush.setSize to change the brush.

Does hiding ink change the source presentation?

No. Calling InkOptions.setHideInk affects only the rendered or exported result; it does not remove or modify ink objects in the source presentation.

Which export formats support ink options?

You can configure ink options for PDF, HTML, SVG, TIFF, and bitmap slide images through the corresponding export or rendering options shown above.

Further reading