I can't get changes made via fpdf_edit.h routines to be serialized by SaveCopy

177 views
Skip to first unread message

Joe Wezorek

unread,
Feb 24, 2021, 12:50:36 PM2/24/21
to pdf...@googlegroups.com
Hi, 
I'm trying to modify existing PDFs via the calls in fpdf_edit.h. If I render after making changes I can see the effect of the calls but when I attempt to serialize the output to a new PDF I either get a blank page or unchanged output depending on whether I pass FPDF_INCREMENTAL to FPDF_SaveAsCopy(...) or not.

Now, I am using a relatively old version of the pdfium codebase. I believe I pulled this code around April of 2019. Would updating Pdfium fix my issues? Updating will be some work for me because I have Pdfium set up as a visual studio solution, which I did by hand, but if it is certain these issues are old code related I'd undertake the effort.

For reference my code looks like the following

ScopedFPDFPage sfpp(FPDF_LoadPage(doc, 0));
auto page = sfpp.get();

FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 2); // modify some object
FPDFPageObj_Transform(obj, 0, 0, 0, 0, 0, 0); // for example
FPDFPage_GenerateContent(page);

// if i render here the object with the zeroed out transform will not be rendered

PdfSaver saver(outputFilename);
FPDF_SaveAsCopy(doc, &saver, 0); // or 1, neither works 

Olivia Yingst

unread,
Feb 24, 2021, 2:21:27 PM2/24/21
to Joe Wezorek, pdfium
Hi Joe,

I know FPDF_SaveAsCopy() had some XFA related changes after April 2019. It might not be related to your case,  but just to be safe, I would recommend updating to the latest PDFium code.

I just tested with the following code on a test.pdf which has 1 text obj in the first page with the latest version of PDFium.

  ASSERT_TRUE(OpenDocument("test.pdf"));
  FPDF_PAGE page = LoadPage(0);
  ASSERT_TRUE(page);
  FPDF_PAGEOBJECT obj = FPDFPage_GetObject(page, 0);

  ASSERT_TRUE(obj);


  FPDFPageObj_Transform(obj, 0, 0, 0, 0, 0, 0);
  FPDFPage_GenerateContent(page);
  FPDF_SaveAsCopy(document(), this,0);

  VerifySavedDocument(400, 600, kChecksum);
  UnloadPage(page);

  ASSERT_TRUE(OpenSavedDocument());
  FPDF_PAGE saved_page = LoadSavedPage(0);
  {
    ScopedFPDFBitmap page_bitmap = RenderPage(saved_page);
    CompareBitmap(page_bitmap.get(), 400, 600, kChecksum);
  }

  CloseSavedPage(saved_page);
  CloseSavedDocument();

By skipping the call FPDFPageObj_Transform(), the rendering result for the saved document does change.

Maybe something is wrong with FPDF_FILEWRITE? Does FPDF_SaveAsCopy() return true on success for your case? I think maybe you can take a look there.
I am wondering whether this issue is happening to all the PDFs or just specific PDFs which you are editing. If there is still a concern after updating the PDFium code, it's better to file a bug through https://bugs.chromium.org/p/pdfium/issues/entry and attach a sample PDF that can trigger the issue.

Thanks,
Olivia

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/CAKpXZPfiDoyDvRoHxMfcvCgRqYY%3D8amCAebZVb7xbUOFRov_2w%40mail.gmail.com.


--

Olivia(Hui) Yingst | Software Engineer | huiy...@google.com | 213-399-8487
Reply all
Reply to author
Forward
0 new messages