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,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3goQDSYgDiGofgAAAslJREFUOMvtlM9LFGEYx7/vvOPM6ywuuyPFihWFBUsdNnA6KLIh+QPx4KWExULdHQ/9A9EfUodYmATDYg/iRewQzklFWxcEBcGgEplDkDtI6sw4PzrIbrOuedBb9MALD7zv+3m+z4/3Bf7bZS2bzQIAcrmcMDExcTeXy10DAFVVAQDksgFUVZ1ljD3yfd+0LOuFpmnvVVW9GHhkZAQcxwkNDQ2FSCQyRMgJxnVdy7KstKZpn7nwha6urqqfTqfPBAJAuVymlNLXoigOhfd5nmeiKL5TVTV+lmIKwAOA7u5u6Lped2BsbOwjY6yf4zgQQkAIAcedaPR9H67r3uYBQFEUFItFtLe332lpaVkUBOHK3t5eRtf1DwAwODiIubk5DA8PM8bYW1EU+wEgCIJqsCAIQAiB7/u253k2BQDDMJBKpa4mEon5eDx+UxAESJL0uK2t7XosFlvSdf0QAEmlUnlRFJ9Waho2Qghc1/U9z3uWz+eX+Wr+lL6SZfleEAQIggA8z6OpqSknimIvYyybSCReMsZ6TislhCAIAti2Dc/zejVNWwCAavN8339j27YbTg0AGGM3WltbP4WhlRWq6Q/btrs1TVsYHx+vNgqKoqBUKn2NRqPFxsbGJzzP05puUlpt0ukyOI6z7zjOwNTU1OLo6CgmJyf/gA3DgKIoWF1d/cIY24/FYgOU0pp0z/Ityzo8Pj5OTk9PbwHA+vp6zWghDC+VSiuRSOQgGo32UErJ38CO42wdHR09LBQK3zKZDDY2NupmFmF4R0cHVlZWlmRZ/iVJUn9FeWWcCCE4ODjYtG27Z2Zm5juAOmgdGAB2d3cBADs7O8uSJN2SZfl+WKlpmpumaT6Yn58vn/fs6XmbhmHMNjc3tzDGFI7jYJrm5vb29sDa2trPC/9aiqJUy5pOp4f6+vqeJ5PJBAB0dnZe/t8NBajx/z37Df5OGX8d13xzAAAAAElFTkSuQmCC); + } } /* Fancy CSS END */ diff --git a/share/pdf2htmlEX.js.in b/share/pdf2htmlEX.js.in index 636c94a..118c8d6 100644 --- a/share/pdf2htmlEX.js.in +++ b/share/pdf2htmlEX.js.in @@ -260,7 +260,24 @@ 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() { + if(this.className.search("checked") == -1) + this.className += " checked"; + else + this.className = "ir"; + }); + } + }, + init_after_loading_content : function() { + this.initialize_radio_button(); + this.sidebar = document.getElementById(this.config['sidebar_id']); this.outline = document.getElementById(this.config['outline_id']); this.container = document.getElementById(this.config['container_id']); 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..b8b0521 --- /dev/null +++ b/src/HTMLRenderer/form.cc @@ -0,0 +1,75 @@ +/* + * 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, width, font_size; + int height; + + w->getRect(&x1, &y1, &x2, &y2); + x1 = x1 * param.zoom; + x2 = x2 * param.zoom; + y1 = y1 * param.zoom; + y2 = y2 * param.zoom; + + width = x2 - x1; + height = y2 - y1; + + if(w->getType() == formText) + { + font_size = height / 2; + + out + << "" << endl; + } + + if(w->getType() == formButton) + { + width += 3; + height += 3; + + out + << "
" << 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@"; + } }