podofo / podofo

A C++17 PDF manipulation library

Home Page:https://podofo.github.io/podofo/documentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I add an text to an existing document?

Dykson opened this issue · comments

Please tell me how to add text to a document page in the new versions of podofo 0.10.x?

...
PdfFont *font;
painter.SetCanvas(page);
font = doc.GetFonts().SearchFont("Arial");
painter.TextState.SetFont(*font, 20);
painter.DrawText("ABCDEFGHIKLMNOPQRSTVXYZ", 10, 10); //error Acrobat 
painter.FinishDrawing();
doc.Save(fn_out);
...

The text is not added, Acrobat throws an error on the page.

The code is correct, but the information is insufficient. Never, ever, assume what is not working for you will also cause troubles for others. Debug the selected font with these lines, post the output here and attach the produced pdf.

The font problem was caused by the fact that the current document to which the text was added was merged with another document by the AppendDocumentPages function. Apparently, I need to re-save the document before merging. Although it seems counterintuitive.