How to perform incremental save in pdfium?

288 views
Skip to first unread message

Suhas Chintala

unread,
Aug 17, 2018, 1:05:39 AM8/17/18
to pdfium
I have tried the FPDF_INCREMENTAL flag to 1. The code currently does not even update the m_newobjnumarray array, hence  the WriteNewObjs function in the cpdf_creator.cpp does not work. The new xref tables are not populated because of that. Have I not missed something? Does calling FPDF_SaveAsCopy() with incremental save flag set work? Or do I need to some preprocessing to get it working?

A small code snippet demonstrating incremental save if at all it is possible in current code would be very helpful. Thanks.

Lei Zhang

unread,
Sep 20, 2018, 1:24:23 AM9/20/18
to Suhas Chintala, pdfium
Do you have a code snippet of your own to show what you are trying to
do? It is certainly possible that FPDF_INCREMENTAL is broken.
> --
> You received this message because you are subscribed to the Google Groups
> "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pdfium+un...@googlegroups.com.
> To post to this group, send email to pdf...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pdfium/e7fdd89d-7da2-466c-ac08-3556bb7b6b0b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ankit Kumar

unread,
Sep 20, 2018, 1:41:18 PM9/20/18
to pdfium
FPDF_INCREMENTAL can't actually do anything since the code below for adding new objects is no-op in case of incremental as on incremental it doesn't add any new objects, it just continues the for loop. Even on removing that part the changed objects are the Appearance streams in cases of form annnotations not the form object itself and we need to rewrite that too since we need to update the AP reference in the object.


void CPDF_Creator::InitNewObjNumOffsets() {
  for (const auto& pair : *m_pDocument) {
    const uint32_t objnum = pair.first;
    if (m_IsIncremental ||
        pair.second->GetObjNum() == CPDF_Object::kInvalidObjNum) {
      continue;
    }
    if (m_pParser && m_pParser->IsValidObjectNumber(objnum) &&
        !m_pParser->IsObjectFree(objnum)) {
      continue;
    }
    m_NewObjNumArray.insert(std::lower_bound(m_NewObjNumArray.begin(),
                                             m_NewObjNumArray.end(), objnum),
                            objnum);
Reply all
Reply to author
Forward
0 new messages