Skip to content

Commit e60c06f

Browse files
author
Sam
committed
support output to STDOUT using '-' as output filename, added --quiet option
1 parent 271bd3a commit e60c06f

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/HTMLRenderer/general.cc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ void HTMLRenderer::process(PDFDoc *doc)
124124
break;
125125
}
126126

127-
cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
127+
if (!param.quiet) {
128+
cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
129+
}
128130

129131
if(param.split_pages)
130132
{
@@ -153,9 +155,10 @@ void HTMLRenderer::process(PDFDoc *doc)
153155
f_curpage = nullptr;
154156
}
155157
}
156-
if(page_count >= 0)
158+
if (!param.quiet && page_count >= 0)
157159
cerr << "Working: " << page_count << "/" << page_count;
158-
cerr << endl;
160+
if (!param.quiet)
161+
cerr << endl;
159162

160163
////////////////////////
161164
// Process Outline
@@ -167,7 +170,8 @@ void HTMLRenderer::process(PDFDoc *doc)
167170
bg_renderer = nullptr;
168171
fallback_bg_renderer = nullptr;
169172

170-
cerr << endl;
173+
if (!param.quiet)
174+
cerr << endl;
171175
}
172176

173177
void HTMLRenderer::setDefaultCTM(double *ctm)
@@ -394,14 +398,21 @@ void HTMLRenderer::post_process(void)
394398
f_css.fs.close();
395399

396400
// build the main HTML file
397-
ofstream output;
398-
{
401+
std::ofstream foutput;
402+
std::streambuf *output_buf;
403+
if(param.output_filename == "-") {
404+
output_buf = std::cout.rdbuf();
405+
}
406+
else {
399407
auto fn = str_fmt("%s/%s", param.dest_dir.c_str(), param.output_filename.c_str());
400-
output.open((char*)fn, ofstream::binary);
401-
if(!output)
408+
foutput.open((char*)fn, ofstream::binary);
409+
if(!foutput)
402410
throw string("Cannot open ") + (char*)fn + " for writing";
403-
set_stream_flags(output);
411+
set_stream_flags(foutput);
412+
413+
output_buf = foutput.rdbuf();
404414
}
415+
std::ostream output(output_buf);
405416

406417
// apply manifest
407418
ifstream manifest_fin((char*)str_fmt("%s/%s", param.data_dir.c_str(), MANIFEST_FILENAME.c_str()), ifstream::binary);

src/Param.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct Param
7777
std::string data_dir;
7878
std::string poppler_data_dir;
7979
std::string tmp_dir;
80+
int quiet;
8081
int debug;
8182
int proof;
8283

src/Preprocessor.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ void Preprocessor::process(PDFDoc * doc)
4545
int page_count = (param.last_page - param.first_page + 1);
4646
for(int i = param.first_page; i <= param.last_page ; ++i)
4747
{
48-
cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
48+
if (!param.quiet)
49+
cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
4950

5051
doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI,
5152
0,
@@ -54,9 +55,10 @@ void Preprocessor::process(PDFDoc * doc)
5455
false, // printing
5556
nullptr, nullptr, nullptr, nullptr);
5657
}
57-
if(page_count >= 0)
58+
if (!param.quiet && page_count >= 0)
5859
cerr << "Preprocessing: " << page_count << "/" << page_count;
59-
cerr << endl;
60+
if (!param.quiet)
61+
cerr << endl;
6062
}
6163

6264
void Preprocessor::drawChar(GfxState *state, double x, double y,

src/pdf2htmlEX.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void parse_options (int argc, char **argv)
199199
.add("tmp-dir", &param.tmp_dir, param.tmp_dir, "specify the location of temporary directory.")
200200
.add("data-dir", &param.data_dir, param.data_dir, "specify data directory")
201201
.add("poppler-data-dir", &param.poppler_data_dir, param.poppler_data_dir, "specify poppler data directory")
202+
.add("quiet", &param.quiet, 0, "do no print processing info")
202203
.add("debug", &param.debug, 0, "print debugging information")
203204
.add("proof", &param.proof, 0, "texts are drawn on both text layer and background for proof.")
204205

0 commit comments

Comments
 (0)