ConvertTextToPaths
Content stream editing, Fonts
Description
Known embedded-font sources retain invalid-code consumption and CID-zero recovery. Truncated multibyte codes do not receive single-byte word spacing, and decoding work-limit failures stop conversion without switching to legacy splitting
Supported embedded composite fonts retain verified one-to-four-byte source decoding and resolved missing-glyph fallback. Conversion uses the original CID widths and source-byte word-spacing rules, and places vertical outlines with the font's vertical origin metrics
Rewrites text-showing instructions on the selected pages as vector Form XObject invocations while retaining glyph placement, text spacing, writing mode, transformations, fill colour, stroke colour, and stroke settings
TrueType and Type 1 glyph outlines are extracted once and reused for repeated glyphs. Type 3 CharProcs are converted into ordinary Form XObjects with their font matrix, bounding box, and resource scope preserved. The original text-showing and font-selection instructions are removed
The conversion is transactional. Every selected content layer and requested nested Form is parsed and converted in memory before any PDF object is changed. Unsupported fonts, text clipping rendering modes 4 through 7 with fonts other than Type 3, malformed text state, and ambiguous shared Form resource scopes fail without partially rewriting the document
Type 3 glyphs add nothing to the clipping path in modes 4 through 7, as ISO 32000-2 specifies, so Type 3 text in those modes is converted: modes 4 to 6 draw the glyph descriptions and mode 7, like mode 3, draws nothing
Converted text is no longer searchable, selectable, or extractable as text. It remains scalable vector content for rendering and printing
Syntax
Delphi
Function TPDFlib.ConvertTextToPaths(Const PageRange: WideString= ''; Options: Integer= PDF_TEXT_PATH_DEFAULT): Integer;
ActiveX
Function PDFlib::ConvertTextToPaths(PageRange As String, Options As Long) As Long
DLL
int DLConvertTextToPaths(int InstanceID, const wchar_t* PageRange, int Options);
int DLConvertTextToPathsA(int InstanceID, const char* PageRange, int Options);
Parameters
| PageRange | Page range expression using one-based page numbers. An empty value selects every page |
|---|---|
| Options | Bitwise combination of PDF_TEXT_PATH_RECURSE_FORMS to convert nested Form XObjects and PDF_TEXT_PATH_PURGE_FONTS to remove source font resources that become unused. PDF_TEXT_PATH_DEFAULT enables both options |
Return values
| 1 or greater | Number of text-showing instructions converted |
|---|---|
| 0 | No eligible text was found, the range or options were invalid, or conversion failed. Inspect LastErrorCode to distinguish errors |
Error codes
| 506 | The source font cannot provide a supported vector glyph program |
|---|---|
| 507 | A text clipping rendering mode requires a clipping path that cannot be represented by an independent glyph Form |
| 508 | The text program, font state, or recursive Form resource scope is malformed or ambiguous |
Example
Converted := PDF.ConvertTextToPaths('1-3,5', PDF_TEXT_PATH_DEFAULT);
If (Converted= 0)and (PDF.LastErrorCode<> 0) Then
raise Exception.Create(PDF.ErrorMessage(PDF.LastErrorCode));