From 27ca8cd07ced05e586d57c35c3d6d5941722e1bd Mon Sep 17 00:00:00 2001 From: Peter Waller Date: Thu, 17 Jan 2019 11:48:22 +0000 Subject: [PATCH] Render filled form fields into Glyphs Now form data will be rendered as usual along with the rest of the content into the output. This changes the page's Glyphs structure to include filled form field characters and their bounding boxes. I have tested this locally on a few PDFs. We should test it a little more. --- src/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8547cbc..29beb06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -308,6 +308,17 @@ void dump_document_meta(const std::string filename, PDFDoc *doc, void TextPageDecRef(TextPage *text_page) { text_page->decRefCnt(); } +void render_annotations(std::unique_ptr &gfx, Annots *annots) { + gfx->saveState(); + + for (auto i = 0; i < annots->getNumAnnots(); i++) { + auto *annot = annots->getAnnot(i); + annot->draw(gfx.get(), false); + } + + gfx->restoreState(); +} + typedef std::unique_ptr TextPagePtr; TextPagePtr page_to_text_page(Page *page) { @@ -319,7 +330,14 @@ TextPagePtr page_to_text_page(Page *page) { -1, -1, -1, -1, false, /* printing */ NULL, NULL)); + gfx->saveState(); page->display(gfx.get()); + gfx->restoreState(); + + // Note: page->getAnnots() contains form fields, so this has the effect of + // rendering form fields. + render_annotations(gfx, page->getAnnots()); + dev->endPage(); return TextPagePtr(dev->takeText(), TextPageDecRef);