diff --git a/AUTHORS b/AUTHORS index 0d5c84b..30b4d98 100644 --- a/AUTHORS +++ b/AUTHORS @@ -17,6 +17,7 @@ Marc Sanfacon Michele Redolfi Mick Giles Ryan Morlok +Simon Chenard Wanmin Liu Packagers: diff --git a/CMakeLists.txt b/CMakeLists.txt index b1f5413..1625b52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,6 +119,7 @@ set(PDF2HTMLEX_SRC ${PDF2HTMLEX_SRC} src/HTMLRenderer/general.cc src/HTMLRenderer/image.cc src/HTMLRenderer/font.cc + src/HTMLRenderer/form.cc src/HTMLRenderer/link.cc src/HTMLRenderer/outline.cc src/HTMLRenderer/state.cc diff --git a/pdf2htmlEX.1.in b/pdf2htmlEX.1.in index 5cf61dc..9c9976d 100644 --- a/pdf2htmlEX.1.in +++ b/pdf2htmlEX.1.in @@ -138,6 +138,10 @@ Whether to show outline in the generated HTML .B \-\-process-annotation <0|1> (Default: 0) Whether to show annotation in the generated HTML +.TP +.B \-\-process-form <0|1> (Default: 0) +Whether to include text fields and radio buttons in the generated HTML + .TP .B \-\-printing <0|1> (Default: 1) Enable printing support. Disabling this option may reduce the size of CSS. diff --git a/share/base.css.in b/share/base.css.in index 7f61507..a15a23f 100644 --- a/share/base.css.in +++ b/share/base.css.in @@ -190,4 +190,14 @@ -ms-transform-origin:0% 100%; -webkit-transform-origin:0% 100%; } +/* for the forms */ +.@CSS_INPUT_TEXT_CN@ { + border: none; + background-color: rgba(255, 255, 255, 0.0); +} + +.@CSS_INPUT_RADIO_CN@:hover { + cursor: pointer; +} + /* Base CSS END */ diff --git a/share/fancy.css.in b/share/fancy.css.in index b8d9dc5..bdba3f6 100644 --- a/share/fancy.css.in +++ b/share/fancy.css.in @@ -81,5 +81,8 @@ -webkit-animation: swing 1.5s ease-in-out 0.01s infinite alternate none; animation: swing 1.5s ease-in-out 0.01s infinite alternate none; } + .@CSS_RADIO_CHECKED_CN@ { + background: no-repeat url(data:image/png;base64,iVBORw0KGgo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SuQmCC); + } } /* Fancy CSS END */ diff --git a/share/pdf2htmlEX.js.in b/share/pdf2htmlEX.js.in index 636c94a..1b00b12 100644 --- a/share/pdf2htmlEX.js.in +++ b/share/pdf2htmlEX.js.in @@ -260,6 +260,18 @@ Viewer.prototype = { this.pre_hide_pages(); }, + initialize_radio_button : function() { + var elements = document.getElementsByClassName('ir'); + + for(var i = 0; i < elements.length; i++) { + var r = elements[i]; + + r.addEventListener('click', function() { + this.classList.toggle("checked"); + }); + } + }, + init_after_loading_content : function() { this.sidebar = document.getElementById(this.config['sidebar_id']); this.outline = document.getElementById(this.config['outline_id']); @@ -312,6 +324,7 @@ Viewer.prototype = { ele.addEventListener('click', self.link_handler.bind(self), false); }); + this.initialize_radio_button(); this.render(); }, diff --git a/src/HTMLRenderer/HTMLRenderer.h b/src/HTMLRenderer/HTMLRenderer.h index ff69ad2..18e395d 100644 --- a/src/HTMLRenderer/HTMLRenderer.h +++ b/src/HTMLRenderer/HTMLRenderer.h @@ -21,6 +21,10 @@ #include #include +// for form.cc +#include +#include + #include "pdf2htmlEX-config.h" #include "Param.h" @@ -161,6 +165,8 @@ protected: void process_outline(void); void process_outline_items(GooList * items); + void process_form(std::ofstream & out); + void set_stream_flags (std::ostream & out); void dump_css(void); diff --git a/src/HTMLRenderer/form.cc b/src/HTMLRenderer/form.cc new file mode 100644 index 0000000..6b51622 --- /dev/null +++ b/src/HTMLRenderer/form.cc @@ -0,0 +1,76 @@ +/* + * form.cc + * + * Handling Forms + * + * by Simon Chenard + * 2014.07.25 + */ + +#include +#include +#include + +#include "HTMLRenderer.h" +#include "util/namespace.h" +#include "util/misc.h" + +namespace pdf2htmlEX { + +using std::ofstream; +using std::cerr; + +void HTMLRenderer::process_form(ofstream & out) +{ + FormPageWidgets * widgets = cur_catalog->getPage(pageNum)->getFormWidgets(); + int num = widgets->getNumWidgets(); + + for(int i = 0; i < num; i++) + { + FormWidget * w = widgets->getWidget(i); + double x1, y1, x2, y2; + + w->getRect(&x1, &y1, &x2, &y2); + x1 = x1 * param.zoom; + x2 = x2 * param.zoom; + y1 = y1 * param.zoom; + y2 = y2 * param.zoom; + + double width = x2 - x1; + double height = y2 - y1; + + if(w->getType() == formText) + { + double font_size = height / 2; + + out << "" << endl; + } + else if(w->getType() == formButton) + { + //Ideally would check w->getButtonType() + //for more specific rendering + width += 3; + height += 3; + + out << "
" << endl; + } + else + { + cerr << "Unsupported form field detected" << endl; + } + } +} + +} diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index cea34ea..6a54194 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -239,6 +239,10 @@ void HTMLRenderer::endPage() { html_text_page.dump_css(f_css.fs); html_text_page.clear(); + // process form + if(param.process_form) + process_form(*f_curpage); + // process links before the page is closed cur_doc->processLinks(this, pageNum); @@ -380,6 +384,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc) void HTMLRenderer::post_process(void) { dump_css(); + // close files if they opened if (param.process_outline) { diff --git a/src/Param.h b/src/Param.h index b2330ed..84fa426 100644 --- a/src/Param.h +++ b/src/Param.h @@ -38,6 +38,7 @@ struct Param int process_nontext; int process_outline; int process_annotation; + int process_form; int correct_text_visibility; int printing; int fallback; diff --git a/src/css_class_names.cmakelists.txt b/src/css_class_names.cmakelists.txt index 9240c6e..067d95a 100644 --- a/src/css_class_names.cmakelists.txt +++ b/src/css_class_names.cmakelists.txt @@ -34,3 +34,6 @@ set(CSS_WIDTH_CN "w") # Width set(CSS_BOTTTOM_CN "y") # Y set(CSS_CSS_DRAW_CN "d") # Draw set(CSS_LINK_CN "l") # Link +set(CSS_INPUT_TEXT_CN "it") # Text input +set(CSS_INPUT_RADIO_CN "ir") # Radio button +set(CSS_RADIO_CHECKED_CN "checked") # Show picture of checked out radio button diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 8009538..8f7edb4 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -164,6 +164,7 @@ void parse_options (int argc, char **argv) .add("process-nontext", ¶m.process_nontext, 1, "render graphics in addition to text") .add("process-outline", ¶m.process_outline, 1, "show outline in HTML") .add("process-annotation", ¶m.process_annotation, 0, "show annotation in HTML") + .add("process-form", ¶m.process_form, 0, "include text fields and radio buttons") .add("printing", ¶m.printing, 1, "enable printing support") .add("fallback", ¶m.fallback, 0, "output in fallback mode") .add("tmp-file-size-limit", ¶m.tmp_file_size_limit, -1, "Maximum size (in KB) used by temporary files, -1 for no limit.") diff --git a/src/util/css_const.h.in b/src/util/css_const.h.in index 143adcb..08c23fc 100644 --- a/src/util/css_const.h.in +++ b/src/util/css_const.h.in @@ -56,6 +56,10 @@ const char * const BOTTOM_CN = "@CSS_BOTTTOM_CN@"; const char * const CSS_DRAW_CN = "@CSS_CSS_DRAW_CN@"; const char * const LINK_CN = "@CSS_LINK_CN@"; +const char * const INPUT_TEXT_CN = "@CSS_INPUT_TEXT_CN@"; +const char * const INPUT_RADIO_CN = "@CSS_INPUT_RADIO_CN@"; +const char * const RADIO_CHECKED_CN = "@CSS_RADIO_CHECKED_CN@"; + } } diff --git a/test/browser_tests.py b/test/browser_tests.py index c6cbba4..0db5cf5 100644 --- a/test/browser_tests.py +++ b/test/browser_tests.py @@ -44,7 +44,7 @@ class BrowserTests(Common): os.path.join(self.TEST_DATA_DIR, filename), htmlfilename ] - + result = self.run_pdf2htmlEX(pdf2htmlEX_args) self.assertIn(htmlfilename, result['output_files'], 'HTML file is not generated') @@ -76,7 +76,7 @@ class BrowserTests(Common): @unittest.skipIf(Common.GENERATING_MODE, 'Do not auto generate reference for test_fail') def test_fail(self): - # The HTML reference is generated manually, which mismatches the PDF + # The HTML reference is generated manually, which mismatches the PDF # To test if the environment can detect any errors # E.g. when network is down, 404 message is shown for any HTML message with self.assertRaises(AssertionError): @@ -91,3 +91,6 @@ class BrowserTests(Common): def test_text_visibility(self): self.run_test_case('text_visibility.pdf', ['--correct-text-visibility', 1]) + def test_process_form(self): + self.run_test_case('with_form.pdf', ['--process-form', 1]) + diff --git a/test/browser_tests/with_form.pdf b/test/browser_tests/with_form.pdf new file mode 100644 index 0000000..e491abf Binary files /dev/null and b/test/browser_tests/with_form.pdf differ diff --git a/test/browser_tests/with_form/bg1.png b/test/browser_tests/with_form/bg1.png new file mode 100644 index 0000000..4528d03 Binary files /dev/null and b/test/browser_tests/with_form/bg1.png differ diff --git a/test/browser_tests/with_form/f1.woff b/test/browser_tests/with_form/f1.woff new file mode 100644 index 0000000..639534b Binary files /dev/null and b/test/browser_tests/with_form/f1.woff differ diff --git a/test/browser_tests/with_form/f2.woff b/test/browser_tests/with_form/f2.woff new file mode 100644 index 0000000..18d9cee Binary files /dev/null and b/test/browser_tests/with_form/f2.woff differ diff --git a/test/browser_tests/with_form/f3.woff b/test/browser_tests/with_form/f3.woff new file mode 100644 index 0000000..ac03c78 Binary files /dev/null and b/test/browser_tests/with_form/f3.woff differ diff --git a/test/browser_tests/with_form/f4.woff b/test/browser_tests/with_form/f4.woff new file mode 100644 index 0000000..82c8772 Binary files /dev/null and b/test/browser_tests/with_form/f4.woff differ diff --git a/test/browser_tests/with_form/f5.woff b/test/browser_tests/with_form/f5.woff new file mode 100644 index 0000000..0af6709 Binary files /dev/null and b/test/browser_tests/with_form/f5.woff differ diff --git a/test/browser_tests/with_form/f6.woff b/test/browser_tests/with_form/f6.woff new file mode 100644 index 0000000..b76a45e Binary files /dev/null and b/test/browser_tests/with_form/f6.woff differ diff --git a/test/browser_tests/with_form/with_form.html b/test/browser_tests/with_form/with_form.html new file mode 100644 index 0000000..4064028 --- /dev/null +++ b/test/browser_tests/with_form/with_form.html @@ -0,0 +1,415 @@ + + + + + + + + + + + + + +
+
Éditions « À Reproduire » Internet : www.envolee.com
Question de textes 4
7
Nom
Mona veut un chien
4 Que veut dire la mère de Mona quand elle dit : « C’est beaucoup de travail, avoir un chien » ?
a) Mona doit faire plus de recherche avant d’être prête à avoir un chien.
b) Les chiens travaillent fort afi n d’être de bons animaux de compagnie pour les gens.
c) Les chiens ont besoin de nourriture et d’exercice. Il faut aussi ramasser leurs dégâts.
d) Mona devra se reposer plus si elle a un chien.
5 Comment Mona a-t-elle acquis autant de connaissances sur les chiens ?
a) En écoutant son enseignante à l’école.
b) En visitant un site Web.
c) En écrivant à la Société protectrice des animaux.
d) En regardant une vidéo sur les chiens.
6 Pourquoi Mona veut-elle un Jack Russell ?
7 Que devra faire Mona même si elle est fatiguée ou qu’il pleut ?
8 Décris physiquement le chien que Mona veut choisir.
9 Quand fait-elle ses recherches sur le Web ?
10 Que contient le site Web préféré de Mona ? Nomme deux éléments.
REPÉRAGE
+
+
+
+
+ + + + + + +
+
+
+
+ +
+
+ +