mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
working but ugly code
This commit is contained in:
parent
f609ed732f
commit
5223541c1f
@ -127,6 +127,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
|
||||
|
@ -20,6 +20,10 @@
|
||||
#include <GfxFont.h>
|
||||
#include <Annot.h>
|
||||
|
||||
// for form.cc
|
||||
#include <Page.h>
|
||||
#include <Form.h>
|
||||
|
||||
#include "pdf2htmlEX-config.h"
|
||||
|
||||
#include "Param.h"
|
||||
@ -165,6 +169,8 @@ protected:
|
||||
void process_outline(void);
|
||||
void process_outline_items(GooList * items);
|
||||
|
||||
void process_form(std::ostream & out);
|
||||
|
||||
void set_stream_flags (std::ostream & out);
|
||||
|
||||
void dump_css(void);
|
||||
|
103
src/HTMLRenderer/form.cc
Normal file
103
src/HTMLRenderer/form.cc
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* form.cc
|
||||
*
|
||||
* Handling Forms
|
||||
*
|
||||
* by Simon Chenard
|
||||
* 2014.07.25
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "HTMLRenderer.h"
|
||||
#include "util/namespace.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
using std::ostream;
|
||||
using std::cerr;
|
||||
|
||||
void HTMLRenderer::process_form(ostream & out)
|
||||
{
|
||||
FormPageWidgets * widgets = cur_catalog->getPage(pageNum)->getFormWidgets();
|
||||
int num = widgets->getNumWidgets();
|
||||
std::ostringstream derp;
|
||||
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
FormWidget * w = widgets->getWidget(i);
|
||||
double x1, y1, x2, y2;
|
||||
int width, height, font_size;
|
||||
|
||||
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 << "<input id=\"text-" << std::to_string(pageNum) << "-"
|
||||
<< std::to_string(i) << "\" type=\"text\" value=\"\""
|
||||
<< " style=\"position: absolute; left: " << std::to_string(x1) <<
|
||||
"px; bottom: " << std::to_string(y1) << "px;" <<
|
||||
"width: " << std::to_string(width) << "px; height: " << std::to_string(height) <<
|
||||
"px; line-height: " << std::to_string(height) << "px; font-size: "
|
||||
<< std::to_string(font_size) << "px;\" class=\"text_input\" />" << endl;
|
||||
}
|
||||
|
||||
if(w->getType() == formButton)
|
||||
{
|
||||
out << "<div id=\"cb-" << std::to_string(pageNum) << "-"
|
||||
<< std::to_string(i) << "\""
|
||||
<< " style=\"opacity:0.0; position: absolute; left: " << std::to_string(x1) <<
|
||||
"px; bottom: " << std::to_string(y1) << "px;" <<
|
||||
"width: " << std::to_string(width) << "px; height: " << std::to_string(height) <<
|
||||
"px; font-size: 20px; \" class=\"checkbox-" <<
|
||||
std::to_string(pageNum) << "\">X</div>" << endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//output, at the end, the necessary css
|
||||
if(num > 0) {
|
||||
//this is usable by the whole document and as such should be in dump_css
|
||||
out << "<style>" <<
|
||||
".text_input {" <<
|
||||
"border: none; " <<
|
||||
"background-color: rgba(255, 255, 255, 0.0);" <<
|
||||
"}" << endl <<
|
||||
".checkbox-" << std::to_string(pageNum) << ":hover {" <<
|
||||
"cursor: pointer;" <<
|
||||
"}" <<
|
||||
"</style>" << endl;
|
||||
|
||||
//this is currently page specific
|
||||
out << "<script type=\"text/javascript\">" << endl <<
|
||||
"var checkboxes = document.getElementsByClassName(\"checkbox-" <<
|
||||
std::to_string(pageNum) << "\");" << endl <<
|
||||
"var c = checkboxes.item(0);" << endl <<
|
||||
"console.log(c);" << endl <<
|
||||
"for(var i = 0; i < checkboxes.length; i++) {" << endl <<
|
||||
"var c = checkboxes[i];" << endl <<
|
||||
"c.addEventListener('click', function() {" << endl <<
|
||||
"if(this.style.opacity == 1)" << endl <<
|
||||
"this.style.opacity = 0;" << endl <<
|
||||
"else" << endl <<
|
||||
"this.style.opacity = 1;" << endl <<
|
||||
"});" << endl <<
|
||||
"}" << endl <<
|
||||
"</script>" << endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -252,6 +252,10 @@ void HTMLRenderer::endPage() {
|
||||
html_text_page.dump_css(f_css.fs);
|
||||
html_text_page.clear();
|
||||
|
||||
// process form
|
||||
if(param.include_forms)
|
||||
process_form(*f_curpage);
|
||||
|
||||
// process links before the page is closed
|
||||
cur_doc->processLinks(this, pageNum);
|
||||
|
||||
|
@ -62,6 +62,9 @@ struct Param
|
||||
int tounicode;
|
||||
int optimize_text;
|
||||
|
||||
// adobe form
|
||||
int include_forms;
|
||||
|
||||
// background image
|
||||
std::string bg_format;
|
||||
int svg_node_count_limit;
|
||||
|
@ -189,6 +189,9 @@ void parse_options (int argc, char **argv)
|
||||
.add("optimize-text", ¶m.optimize_text, 0, "try to reduce the number of HTML elements used for text")
|
||||
.add("correct-text-visibility", ¶m.correct_text_visibility, 0, "try to detect texts covered by other graphics and properly arrange them")
|
||||
|
||||
// adobe forms
|
||||
.add("include-forms", ¶m.include_forms, 0, "include text fields and such")
|
||||
|
||||
// background image
|
||||
.add("bg-format", ¶m.bg_format, "png", "specify background image format")
|
||||
.add("svg-node-count-limit", ¶m.svg_node_count_limit, -1, "if node count in a svg background image exceeds this limit,"
|
||||
|
Loading…
Reference in New Issue
Block a user