Skip to content

Commit

Permalink
Render filled form fields into Glyphs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pwaller committed Jan 17, 2019
1 parent ea414b4 commit 27ca8cd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> &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<TextPage, decltype(&TextPageDecRef)> TextPagePtr;

TextPagePtr page_to_text_page(Page *page) {
Expand All @@ -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);
Expand Down

0 comments on commit 27ca8cd

Please sign in to comment.