Using SetTextData to update existing text element

Product: PDFNetCMac

Product Version: 10.2.0-f07f0d288b

Please describe your issue and provide steps to reproduce it:

I’m trying to modify the text in a text element (think splitting a word into two and use different font for each piece)

I have managed to prototype using python

    bf = Font.CreateTrueTypeFont(doc.GetSDFDoc(), FONT_PATH )
    data_ = element.GetTextData()
    element.SetTextData(data_[:2], len(data_[:2]) )
    gs.SetFont(bf, font_size)

I’ve failed to get this working in Go or C++. I can get the text characters updated, but obviously the font mapping is incorrect…

    el().SetTextData( head_bytes, head_byte_count);

    pdftron::PDF::Font bf = pdftron::PDF::Font::CreateCIDTrueTypeFont(
                                    true, true,
                                    pdftron::PDF::Font::Encoding::e_Indices );

    // this doesn't work
    // gstate.SetFont(bf, font_size);


The whole API between TextData and TextString seems unusual. Is there a means to use unicode/string to set the text in an EXISTING element ?

1 Like

Hi Richard,

Can you please elaborate on what you are trying to achieve? Can you please share the input files you are working with and the output you are generating with your python script?

Your C++ code appears to be running different methods. In the Python example you use CreateTrueTypeFont(PDFDoc, string), but in the C++ example you are using CreateCIDTrueTypeFont(PDFDoc, string, bool, bool, Encoding). Is there a reason for the change?

1 Like


High level goal is to build software help me read academic papers/patents - my ADHD really makes it hard to work my way through text heavy documents. I discovered a concept where changing the display of characters in a word (i.e using fonts/colors) can help some neurodivergent people read so I’m experimenting with the concept.

I switched to trying Go or C++ to make it easier to distribute pre-compiled binaries of the software to my niece (who also has ADHD).

I’ve attached the input file and the corresponding output file using the python code.

I’m using apryse-sdk 10.1.0

As for the C++ discrepancy - I was just testing if using the CID api made any difference - it didn’t.



1 Like

The output file probably needs to be downloaded to view it, it looks okay on my desktop, but appears corrupted when view directly in the GitHub viewer.

1 Like

I’m still blocked by this and have even researched switching to another PDF library.

But given time constraints I think I’ll have to back to using python bindings.

1 Like