diff --git a/src/pdf/api/qpdfdocument_p.h b/src/pdf/api/qpdfdocument_p.h index 9a737766..902f2b4c 100644 --- a/src/pdf/api/qpdfdocument_p.h +++ b/src/pdf/api/qpdfdocument_p.h @@ -51,6 +51,7 @@ #include "qpdfdocument.h" #include "third_party/pdfium/public/fpdfview.h" +#include "third_party/pdfium/public/fpdf_formfill.h" #include "third_party/pdfium/public/fpdf_dataavail.h" #include @@ -76,6 +77,8 @@ public: FPDF_AVAIL avail; FPDF_DOCUMENT doc; + FPDF_FORMFILLINFO formfillinfo; + FPDF_FORMHANDLE form_handle; bool loadComplete; QPointer device; diff --git a/src/pdf/qpdfdocument.cpp b/src/pdf/qpdfdocument.cpp index c07ec90c..160ca273 100644 --- a/src/pdf/qpdfdocument.cpp +++ b/src/pdf/qpdfdocument.cpp @@ -65,6 +65,7 @@ QPdfMutexLocker::QPdfMutexLocker() QPdfDocumentPrivate::QPdfDocumentPrivate() : avail(nullptr) , doc(nullptr) + , form_handle(nullptr) , loadComplete(false) , status(QPdfDocument::Null) , lastError(QPdfDocument::NoError) @@ -90,6 +91,10 @@ QPdfDocumentPrivate::QPdfDocumentPrivate() // FX_DOWNLOADHINTS setup FX_DOWNLOADHINTS::version = 1; AddSegment = fpdf_AddSegment; + + // FPDF_FORMFILLINFO setup + memset(&formfillinfo, 0, sizeof(formfillinfo)); + formfillinfo.version = 1; } QPdfDocumentPrivate::~QPdfDocumentPrivate() @@ -106,6 +111,10 @@ void QPdfDocumentPrivate::clear() { QPdfMutexLocker lock; + if (form_handle) + FPDFDOC_ExitFormFillEnvironment(form_handle); + form_handle = nullptr; + if (doc) FPDF_CloseDocument(doc); doc = nullptr; @@ -292,6 +301,10 @@ void QPdfDocumentPrivate::tryLoadDocument() Q_ASSERT(!doc); doc = FPDFAvail_GetDocument(avail, password); + + if (doc) + form_handle = FPDFDOC_InitFormFillEnvironment(doc, &formfillinfo); + lock.unlock(); updateLastError(); @@ -772,6 +785,7 @@ QImage QPdfDocument::render(int page, QSize imageSize, QPdfDocumentRenderOptions << "size" << imageSize << "took" << timer.elapsed() << "ms"; } else { FPDF_RenderPageBitmap(bitmap, pdfPage, 0, 0, result.width(), result.height(), rotation, flags); + FPDF_FFLDraw(d->form_handle, bitmap, pdfPage, 0, 0, result.width(), result.height(), rotation, flags); qCDebug(qLcDoc) << "page" << page << "size" << imageSize << "took" << timer.elapsed() << "ms"; }