Let's say you have a page "PdfPage *page". You can get contents:
PdfObject *contents = page->GetObject()->GetIndirectKey("Contents"); Contents now can be PdfDictionary or PdfArray of PdfDictionary if I am not wrong so you need to handle both situations (and also a situation where there are no contents at all). All cases which you need to handle can be read from the pdf reference or you can also check podofo source code what is doing for example "PdfPainter::SetPage". Now let's assume it is an array. You can either prepend "q" at beginning of first contents entry or prepend new entry into array with sole operator "q" (which is my preferred and simpler way as it does not need to recompress anything): PdfObject *q = page->GetObject()->GetOwner()->CreateObject(); q->GetStream()->Set("q"); // painter.Save() inserts "q" contents->GetArray().insert(contents->GetArray().begin(), q->Reference()); Now you can draw into page as usual but before any drawing insert "Q" (but my preferred way is to append new contents entry for new drawing): painter.SetPage(page); painter.Restore(); // this appends "Q" painter.DrawLine(... In your case the contents is not array. There is some hint how to make it array: PdfArray arr; arr.push_back(contents->Reference()); // ensure for example that contents has a valid reference - so it is indirect object as should be like this "contents->Reference().ObjectNumber() > 0" page->GetObject()->GetDictionary().AddKey("Contents", arr); contents = page->GetObject()->GetDictionary().GetKey("Contents"); // if you need PdfObject to continue or you can directly modify "arr" before adding it as "Contents" key. On Sun, Mar 14, 2021 at 6:26 PM Kegin <kegin7...@gmail.com> wrote: > Thank you for your reply > > But ... sorry, I understand what you mean, but I don’t know about the > structure of pdf. > > In MacOS, build the library seem very hard for me, because i unfamiliar > the cmake, > I use the podofo-library that it have been built , so... I can't track the > source code, > > Is there an easy way to solve it? > > For example, using the podofo-lib to add'q' and'Q' by some function, > I already try to use the podofo to resave pdf, but it don't changed. > > In addition, can you please help me modify the part of the pdf you > mentioned and send the pdf, > let me compare and study it? > > > > > >
_______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users