Hi,
PDFium has some PDF editing features, exposed mainly through fpdf_edit.h and fpdf_annot.h. I'm considering using PDFium as backend API for a PDF editor.
For reading the input file, you need to implement FPDF_FILEACCESS by passing a function to its member m_GetBlock. That method is called e.g. every time you call FPDF_LoadPage.
Once you've made changes to your FPDF_DOCUMENT and its FPDF_PAGEs, you save it using one of the functions declared in fpdf_save.h, e.g. FPDF_SaveAsCopy, which takes a FPDF_FILEWRITE. Similarly to m_GetBlock in FPDF_FILEACCESS on the reading side, FPDF_FILEWRITE needs a function WriteBlock (naming and parameter types seem a bit inconsistent, no "m_" prefix here).
So m_GetBlock and WriteBlock will operate block-wise on the input and output file, respectively, reading an unsigned char *pBuf from the input file, and writing a const void* pData to the output file (consistency could be improved a bit here).
Please correct me if I'm wrong, but the input file and the output file need to be different files. In an editor you expect to repeatedly make changes, undo/redo, save, make changes and save again, ideally without keeping all FPDF_PAGEs in memory, so both m_GetBlock and WriteBlock will be called as long as the user is using the editor.
I wonder what's best practice here. Here's one idea.
When opening a document, make a temporary file copy and have m_GetBlock operate on it as long as the document is open. Every time the user hits Save, FPDF_SaveAsCopy overwrites the original file via WriteBlock (here's the dangerous part :)). When the document is closed, the temporary file is deleted.
Please let me know if this makes sense or if I'm missing something.
Thanks,
Ralf