1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

Added a parameter to limit the output size. This is an estimate, but should be good enough.

This commit is contained in:
Marc Sanfacon 2013-11-22 16:39:28 -05:00
parent 589047144a
commit 57c02b1972
5 changed files with 62 additions and 43 deletions

View File

@ -109,6 +109,11 @@ void HTMLRenderer::process(PDFDoc *doc)
int page_count = (param.last_page - param.first_page + 1);
for(int i = param.first_page; i <= param.last_page ; ++i)
{
if (param.max_size != -1 && tmp_files.get_total_size() > param.max_size * 1024) {
cerr << "Stop processing, reach max size\n";
break;
}
cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
if(param.split_pages)

View File

@ -31,6 +31,7 @@ struct Param
int embed_javascript;
int embed_outline;
int split_pages;
int max_size;
std::string dest_dir;
std::string css_filename;
std::string page_filename;
@ -69,6 +70,7 @@ struct Param
// misc.
int clean_tmp;
std::string data_dir;
std::string basetmp_dir;
int css_draw;
int debug;

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <cstdio>
#include <sys/stat.h>
#include "TmpFiles.h"
#include "Param.h"
@ -54,5 +55,16 @@ void TmpFiles::clean()
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
}
double TmpFiles::get_total_size() const
{
double total_size = 0;
struct _stat st;
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) {
_stat(iter->c_str(), &st);
total_size += st.st_size;
}
return total_size;
}
} // namespace pdf2htmlEX

View File

@ -14,6 +14,7 @@ public:
~TmpFiles();
void add( const std::string& fn);
double get_total_size() const;
private:
void clean();

View File

@ -141,7 +141,6 @@ void prepare_directories()
stringstream ss;
ss << setw(6) << rand_value;
std::cout << "1- " << tmp_dir << endl;
tmp_dir.erase(tmp_dir.size() - 6);
param.tmp_dir = tmp_dir + ss.str();
::CreateDirectory(param.tmp_dir.c_str(), NULL);
@ -170,6 +169,7 @@ void parse_options (int argc, char **argv)
.add("embed-image", &param.embed_image, 1, "embed image files into output")
.add("embed-javascript", &param.embed_javascript, 1, "embed JavaScript files into output")
.add("embed-outline", &param.embed_outline, 1, "embed outlines into output")
.add("max-output-size", &param.max_size, -1, "maximum output size, in KB (-1 for no max)")
.add("split-pages", &param.split_pages, 0, "split pages into separate files")
.add("dest-dir", &param.dest_dir, ".", "specify destination directory")
.add("css-filename", &param.css_filename, "", "filename of the generated css file")
@ -390,7 +390,6 @@ int main(int argc, char **argv)
cerr << "temporary dir: " << (param.tmp_dir) << endl;
}
exit(0);
try
{
create_directories(param.dest_dir);