From e60c06f14a2f8bb81011abaa746a08e5225311e9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Jun 2016 23:36:32 +0200 Subject: [PATCH 1/2] support output to STDOUT using '-' as output filename, added --quiet option --- src/HTMLRenderer/general.cc | 29 ++++++++++++++++++++--------- src/Param.h | 1 + src/Preprocessor.cc | 8 +++++--- src/pdf2htmlEX.cc | 1 + 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/HTMLRenderer/general.cc b/src/HTMLRenderer/general.cc index 6a54194e5..321a8bf90 100644 --- a/src/HTMLRenderer/general.cc +++ b/src/HTMLRenderer/general.cc @@ -124,7 +124,9 @@ void HTMLRenderer::process(PDFDoc *doc) break; } - cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush; + if (!param.quiet) { + cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush; + } if(param.split_pages) { @@ -153,9 +155,10 @@ void HTMLRenderer::process(PDFDoc *doc) f_curpage = nullptr; } } - if(page_count >= 0) + if (!param.quiet && page_count >= 0) cerr << "Working: " << page_count << "/" << page_count; - cerr << endl; + if (!param.quiet) + cerr << endl; //////////////////////// // Process Outline @@ -167,7 +170,8 @@ void HTMLRenderer::process(PDFDoc *doc) bg_renderer = nullptr; fallback_bg_renderer = nullptr; - cerr << endl; + if (!param.quiet) + cerr << endl; } void HTMLRenderer::setDefaultCTM(double *ctm) @@ -394,14 +398,21 @@ void HTMLRenderer::post_process(void) f_css.fs.close(); // build the main HTML file - ofstream output; - { + std::ofstream foutput; + std::streambuf *output_buf; + if(param.output_filename == "-") { + output_buf = std::cout.rdbuf(); + } + else { auto fn = str_fmt("%s/%s", param.dest_dir.c_str(), param.output_filename.c_str()); - output.open((char*)fn, ofstream::binary); - if(!output) + foutput.open((char*)fn, ofstream::binary); + if(!foutput) throw string("Cannot open ") + (char*)fn + " for writing"; - set_stream_flags(output); + set_stream_flags(foutput); + + output_buf = foutput.rdbuf(); } + std::ostream output(output_buf); // apply manifest ifstream manifest_fin((char*)str_fmt("%s/%s", param.data_dir.c_str(), MANIFEST_FILENAME.c_str()), ifstream::binary); diff --git a/src/Param.h b/src/Param.h index 571fa28d6..b6abb5709 100644 --- a/src/Param.h +++ b/src/Param.h @@ -77,6 +77,7 @@ struct Param std::string data_dir; std::string poppler_data_dir; std::string tmp_dir; + int quiet; int debug; int proof; diff --git a/src/Preprocessor.cc b/src/Preprocessor.cc index a8859ad52..062c5d8a5 100644 --- a/src/Preprocessor.cc +++ b/src/Preprocessor.cc @@ -45,7 +45,8 @@ void Preprocessor::process(PDFDoc * doc) int page_count = (param.last_page - param.first_page + 1); for(int i = param.first_page; i <= param.last_page ; ++i) { - cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush; + if (!param.quiet) + cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush; doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI, 0, @@ -54,9 +55,10 @@ void Preprocessor::process(PDFDoc * doc) false, // printing nullptr, nullptr, nullptr, nullptr); } - if(page_count >= 0) + if (!param.quiet && page_count >= 0) cerr << "Preprocessing: " << page_count << "/" << page_count; - cerr << endl; + if (!param.quiet) + cerr << endl; } void Preprocessor::drawChar(GfxState *state, double x, double y, diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index cf568b210..00a41f453 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -199,6 +199,7 @@ void parse_options (int argc, char **argv) .add("tmp-dir", ¶m.tmp_dir, param.tmp_dir, "specify the location of temporary directory.") .add("data-dir", ¶m.data_dir, param.data_dir, "specify data directory") .add("poppler-data-dir", ¶m.poppler_data_dir, param.poppler_data_dir, "specify poppler data directory") + .add("quiet", ¶m.quiet, 0, "do no print processing info") .add("debug", ¶m.debug, 0, "print debugging information") .add("proof", ¶m.proof, 0, "texts are drawn on both text layer and background for proof.") From 3f231fd21725510321cf3a62efbc1817f9d5ad25 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 Jul 2016 00:22:59 +0200 Subject: [PATCH 2/2] check embed parameters when output redirected to stdout --- src/pdf2htmlEX.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 00a41f453..eebbc912d 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -334,6 +334,13 @@ void check_param() } #endif + if (param.output_filename == "-" && + (!param.embed_css || !param.embed_font || !param.embed_image || !param.embed_javascript + || !param.embed_outline || !param.embed_external_font)) { + cerr << "output redirected to STDOUT, but some html parts set to be not embededed." << endl; + exit(EXIT_FAILURE); + } + if((param.font_format == "ttf") && (param.external_hint_tool == "")) { cerr << "Warning: No hint tool is specified for truetype fonts, the result may be rendered poorly in some circumstances." << endl;