Replace text and font

Hi all,
I would like to replace text in PDF files. The text is placed in an element which I know, with a font that I have installed on my computer (HeleveticaNeue Black) and which is partially embedded in the document.
The aim is to replace the font file to include missing glyphs or create a new font object in the document and link the element to this new embedded font using the swap method for instance.
I already tried to replace the font file and modify the widths array but it doesn’t worked.
Can someone point me to the right direction ?
I read the forum with “replace text” finding terms but I didn’t find anything that works for me.
I found an example to create new Type1 font but mine is a Type3 font if I am not wrong.
Thanks in advance,
Frederic

Could you clarify exactly why replacing text and fonts in a PDF is important for you?

This is often a difficult thing to do, and knowing your objective, I might be able to suggest an easier solution.

Hello,
We are using PDF files to agree with customer on what we will produce.
Sometime, the customer want to order the same thing.
So the aim is to open the old file, change the production order and the date with new ones and save it under the new production order number to avoid manual operations which are not a added value.
I can’t simply remove the stream and recreate a new one because it is a complexe object interpreted by the software used to generate the PDF. If I replace the stream by a “simple” text stream I will lost the automation from the software.
I hope it is more clear.
Thanks in advance,
Frederic
Le mercredi 8 février 2017 18:57:33 UTC+1, Ryan a écrit :

Could you clarify exactly why replacing text and fonts in a PDF is important for you?

This is often a difficult thing to do, and knowing your objective, I might be able to suggest an easier solution.

In that case, you should take a look at our ContentReplacer class and sample, as that probably does what you require.

https://www.pdftron.com/pdfnet/samplecode.html#ContentReplacer

http://www.pdftron.com/pdfnet/docs/PDFNet/?topic=html/T_pdftron_PDF_ContentReplacer.htm

Hello,
I attached the file which I try to modify. The modification is composed of 2 steps :

  • Replace the base line (“G00016 01” and “05/01/2016 08:01:59”) with new text
  • Remove totally the green upper right text (“PGRASSART”, “05/01/2016” and “10:09”)
    I achieve the first step by editing cos objects. I replaced the data stream and I replaced the datafont file with the complete fontfile.
    I can’t achieve the second step, the text seems to be drawn by a type 4 function if I not wrong.
    The datastream is composed of PostScript operators that I don’t understand…
    So I tried the content replacer but I didn’t achive my goal.
    Do you have an idea on how should I proceed ?
    Thanks in advance,
    Frederic
    Le vendredi 10 février 2017 01:54:05 UTC+1, Ryan a écrit :

In that case, you should take a look at our ContentReplacer class and sample, as that probably does what you require.

https://www.pdftron.com/pdfnet/samplecode.html#ContentReplacer

http://www.pdftron.com/pdfnet/docs/PDFNet/?topic=html/T_pdftron_PDF_ContentReplacer.htm

Ideally there is some sort of heuristic you can rely on, to help with ContentReplacer.

For example, are the two cases of text you want to replace always in the same location? If so, then you can use ContentReplacer to replace all text in that area.

Or, is there some unique text keyword you can rely on? If so, you can use the TextSearch class to find that exact text, and then use ContentReplacer to replace for you.

If you can you want to use our high level classes like ContentReplacer, and TextSearch, as those classes take care of a LOT of technical issues. Operating at the object level, like you are with COSEdit generally requires an understanding of the PDF standard.

If you are still stuck with ContentReplacer, please provide additional details on what you did, and what you expected to get.

I have a similar need as the original poster. I need to use a set of complex regular expressions to match a string against the entire document text as seen as one long string. Then the matched string (characters, etc.) need to be removed from the document leaving the rest of the document intact. How do I do this?

Hello,

You can use the TextSearch class to identify and match strings in documents and use the redactor class to redact it from the document.

Please see the following samples for more information:
https://www.pdftron.com/documentation/samples/cs/TextSearchTest?platforms=windows
https://www.pdftron.com/documentation/samples/cs/PDFRedactTest?platforms=windows

Please let me know if you have any further questions.