Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

DynaPDF.ClipPath

This function marks the current path as clipping path.

Component Version macOS Windows Linux Server iOS SDK
DynaPDF 3.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "DynaPDF.ClipPath"; PDF; ClipMode; FillMode )   More

Parameters

Parameter Description Example
PDF The PDF reference returned from DynaPDF.New. $pdf
ClipMode The clipping mode. Can be EvenOdd for using the Even-Odd rule or winding for using the nonzero Winding Number rule. "winding"
FillMode Fill mode. Can be FillNoClose, StrokeNoClose, FillStrokeNoClose, Fill, Stroke, FillStroke, FillEvOdd, FillStrokeEvOdd, FillEvOddNoClose, FillStrokeEvOddNoClose, NoFill or Close. "fill"

Result

Returns OK or error.

Description

This function marks the current path as clipping path.
The function must be called after a closable path was created. A path that consists of a DynaPDF.MoveTo and DynaPDF.LineTo only call cannot be closed!
A clipping path can also be filled, stroked, or both in one pass. However, the combination of a clipping path operator with a path painting operator is seldom used and not supported in all PDF viewers. To avoid unnecessary problems a path should always be clipped and painted in two separate steps, also if this causes some unnecessary overhead.
Once the clipping was created and activated with DynaPDF.ClipPath you can draw arbitrary contents into it, such as images, text, or vector graphics.
A clipping path is part of the current graphics state. The only way to deactivate a clipping path is to restore the graphics state with DynaPDF.RestoreGraphicState. This assumes that it was saved with DynaPDF.SaveGraphicState before the clipping path was created.
Note that it is not possible to extend or widen an active clipping path. It is only possible to intersect it with a new one. The intersection of two clipping paths is never larger than the initial clipping path.
Remarks:
Text objects are handled separately in PDF for use as clipping path. See DynaPDF.SetTextDrawMode for further information.

See also ClipPath function in DynaPDF manual.

Examples

Clip image to circle:

# Initialize DynaPDF if needed
If [ MBS("DynaPDF.IsInitialized") ≠ 1 ]
    Perform Script [ “InitDynaPDF” ]
End If
# Clear current PDF document
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]
# Add image on page
Set Variable [ $destPage ; Value: 1 ]
Set Variable [ $r ; Value: MBS("DynaPDF.AppendPage"; $pdf) ]
# no recompression if possible! But if needed, we use JPEG 90%
Set Variable [ $r ; Value: MBS("DynaPDF.SetSaveNewImageFormat"; $pdf; 0) ]
Set Variable [ $r ; Value: MBS("DynaPDF.SetJPEGQuality"; $pdf; 90) ]
Set Variable [ $r ; Value: MBS("DynaPDF.SetCompressionFilter"; $pdf; "jpeg") ]
# Save old state to restore later
Set Variable [ $r ; Value: MBS( "DynaPDF.SaveGraphicState"; $pdf ) ]
# Draw circle for clipping
Set Variable [ $r ; Value: MBS( "DynaPDF.DrawCircle"; $pdf; 260; 220; 100; "nofill" ) ]
Set Variable [ $r ; Value: MBS( "DynaPDF.ClipPath"; $pdf; "Winding"; "fill" ) ]
# Draw clipped image
Set Variable [ $r ; Value: MBS("DynaPDF.InsertImage"; $pdf; Merge PDFs::InputImage; 100; 100; 320; 200) ]
# restore graphics static to get unclipped drawing
Set Variable [ $r ; Value: MBS( "DynaPDF.RestoreGraphicState"; $pdf ) ]
# Close page and store PDF in container
Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ]
Set Field [ Merge PDFs::FinalPDF ; MBS("DynaPDF.Save"; $pdf; "Merged.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 17th January 2019


DynaPDF.ClearLicense - DynaPDF.CloseImportFile