pdftohtml.cc (xpdf-4.03) | : | pdftohtml.cc (xpdf-4.04) | ||
---|---|---|---|---|
skipping to change at line 34 | skipping to change at line 34 | |||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | |||
static GBool createIndex(char *htmlDir); | static GBool createIndex(char *htmlDir); | |||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | |||
static int firstPage = 1; | static int firstPage = 1; | |||
static int lastPage = 0; | static int lastPage = 0; | |||
static double zoom = 1; | static double zoom = 1; | |||
static int resolution = 150; | static int resolution = 150; | |||
static double vStretch = 1; | ||||
static GBool embedBackground = gFalse; | ||||
static GBool noFonts = gFalse; | static GBool noFonts = gFalse; | |||
static GBool embedFonts = gFalse; | ||||
static GBool skipInvisible = gFalse; | static GBool skipInvisible = gFalse; | |||
static GBool allInvisible = gFalse; | static GBool allInvisible = gFalse; | |||
static GBool formFields = gFalse; | ||||
static GBool tableMode = gFalse; | ||||
static char ownerPassword[33] = "\001"; | static char ownerPassword[33] = "\001"; | |||
static char userPassword[33] = "\001"; | static char userPassword[33] = "\001"; | |||
static GBool verbose = gFalse; | ||||
static GBool quiet = gFalse; | static GBool quiet = gFalse; | |||
static char cfgFileName[256] = ""; | static char cfgFileName[256] = ""; | |||
static GBool printVersion = gFalse; | static GBool printVersion = gFalse; | |||
static GBool printHelp = gFalse; | static GBool printHelp = gFalse; | |||
static ArgDesc argDesc[] = { | static ArgDesc argDesc[] = { | |||
{"-f", argInt, &firstPage, 0, | {"-f", argInt, &firstPage, 0, | |||
"first page to convert"}, | "first page to convert"}, | |||
{"-l", argInt, &lastPage, 0, | {"-l", argInt, &lastPage, 0, | |||
"last page to convert"}, | "last page to convert"}, | |||
{"-z", argFP, &zoom, 0, | {"-z", argFP, &zoom, 0, | |||
"initial zoom level (1.0 means 72dpi)"}, | "initial zoom level (1.0 means 72dpi)"}, | |||
{"-r", argInt, &resolution, 0, | {"-r", argInt, &resolution, 0, | |||
"resolution, in DPI (default is 150)"}, | "resolution, in DPI (default is 150)"}, | |||
{"-nofonts", argFlag, &noFonts, 0, | {"-vstretch", argFP, &vStretch, 0, | |||
"vertical stretch factor (1.0 means no stretching)"}, | ||||
{"-embedbackground", argFlag, &embedBackground, 0, | ||||
"embed the background image as base64-encoded data" }, | ||||
{"-nofonts", argFlag, &noFonts, 0, | ||||
"do not extract embedded fonts"}, | "do not extract embedded fonts"}, | |||
{"-skipinvisible", argFlag, &skipInvisible, 0, | {"-embedfonts", argFlag, &embedFonts, 0, | |||
"embed the fonts as base64-encoded data" }, | ||||
{"-skipinvisible", argFlag, &skipInvisible, 0, | ||||
"do not draw invisible text"}, | "do not draw invisible text"}, | |||
{"-allinvisible", argFlag, &allInvisible, 0, | {"-allinvisible", argFlag, &allInvisible, 0, | |||
"treat all text as invisible"}, | "treat all text as invisible"}, | |||
{"-opw", argString, ownerPassword, sizeof(ownerPassword), | {"-formfields", argFlag, &formFields, 0, | |||
"convert form fields to HTML"}, | ||||
{"-table", argFlag, &tableMode, 0, | ||||
"use table mode for text extraction"}, | ||||
{"-opw", argString, ownerPassword, sizeof(ownerPassword), | ||||
"owner password (for encrypted files)"}, | "owner password (for encrypted files)"}, | |||
{"-upw", argString, userPassword, sizeof(userPassword), | {"-upw", argString, userPassword, sizeof(userPassword), | |||
"user password (for encrypted files)"}, | "user password (for encrypted files)"}, | |||
{"-q", argFlag, &quiet, 0, | {"-verbose", argFlag, &verbose, 0, | |||
"print per-page status information"}, | ||||
{"-q", argFlag, &quiet, 0, | ||||
"don't print any messages or errors"}, | "don't print any messages or errors"}, | |||
{"-cfg", argString, cfgFileName, sizeof(cfgFileName), | {"-cfg", argString, cfgFileName, sizeof(cfgFileName), | |||
"configuration file to use in place of .xpdfrc"}, | "configuration file to use in place of .xpdfrc"}, | |||
{"-v", argFlag, &printVersion, 0, | {"-v", argFlag, &printVersion, 0, | |||
"print copyright and version info"}, | "print copyright and version info"}, | |||
{"-h", argFlag, &printHelp, 0, | {"-h", argFlag, &printHelp, 0, | |||
"print usage information"}, | "print usage information"}, | |||
{"-help", argFlag, &printHelp, 0, | {"-help", argFlag, &printHelp, 0, | |||
"print usage information"}, | "print usage information"}, | |||
{"--help", argFlag, &printHelp, 0, | {"--help", argFlag, &printHelp, 0, | |||
"print usage information"}, | "print usage information"}, | |||
{"-?", argFlag, &printHelp, 0, | {"-?", argFlag, &printHelp, 0, | |||
"print usage information"}, | "print usage information"}, | |||
{NULL} | {NULL} | |||
}; | }; | |||
//------------------------------------------------------------------------ | //------------------------------------------------------------------------ | |||
static int writeToFile(void *file, const char *data, int size) { | static int writeToFile(void *file, const char *data, int size) { | |||
return (int)fwrite(data, 1, size, (FILE *)file); | return (int)fwrite(data, 1, size, (FILE *)file); | |||
} | } | |||
skipping to change at line 114 | skipping to change at line 132 | |||
fprintf(stderr, "%s\n", xpdfCopyright); | fprintf(stderr, "%s\n", xpdfCopyright); | |||
if (!printVersion) { | if (!printVersion) { | |||
printUsage("pdftohtml", "<PDF-file> <html-dir>", argDesc); | printUsage("pdftohtml", "<PDF-file> <html-dir>", argDesc); | |||
} | } | |||
goto err0; | goto err0; | |||
} | } | |||
fileName = argv[1]; | fileName = argv[1]; | |||
htmlDir = argv[2]; | htmlDir = argv[2]; | |||
// read config file | // read config file | |||
if (cfgFileName[0] && !pathIsFile(cfgFileName)) { | ||||
error(errConfig, -1, "Config file '{0:s}' doesn't exist or isn't a file", | ||||
cfgFileName); | ||||
} | ||||
globalParams = new GlobalParams(cfgFileName); | globalParams = new GlobalParams(cfgFileName); | |||
if (verbose) { | ||||
globalParams->setPrintStatusInfo(verbose); | ||||
} | ||||
if (quiet) { | if (quiet) { | |||
globalParams->setErrQuiet(quiet); | globalParams->setErrQuiet(quiet); | |||
} | } | |||
globalParams->setupBaseFonts(NULL); | globalParams->setupBaseFonts(NULL); | |||
globalParams->setTextEncoding("UTF-8"); | globalParams->setTextEncoding("UTF-8"); | |||
// open PDF file | // open PDF file | |||
if (ownerPassword[0] != '\001') { | if (ownerPassword[0] != '\001') { | |||
ownerPW = new GString(ownerPassword); | ownerPW = new GString(ownerPassword); | |||
} else { | } else { | |||
skipping to change at line 169 | skipping to change at line 194 | |||
// create HTML directory | // create HTML directory | |||
if (makeDir(htmlDir, 0755)) { | if (makeDir(htmlDir, 0755)) { | |||
error(errIO, -1, "Couldn't create HTML output directory '{0:s}'", | error(errIO, -1, "Couldn't create HTML output directory '{0:s}'", | |||
htmlDir); | htmlDir); | |||
exitCode = 2; | exitCode = 2; | |||
goto err1; | goto err1; | |||
} | } | |||
// set up the HTMLGen object | // set up the HTMLGen object | |||
htmlGen = new HTMLGen(resolution); | htmlGen = new HTMLGen(resolution, tableMode); | |||
if (!htmlGen->isOk()) { | if (!htmlGen->isOk()) { | |||
exitCode = 99; | exitCode = 99; | |||
goto err1; | goto err1; | |||
} | } | |||
htmlGen->setZoom(zoom); | htmlGen->setZoom(zoom); | |||
htmlGen->setVStretch(vStretch); | ||||
htmlGen->setDrawInvisibleText(!skipInvisible); | htmlGen->setDrawInvisibleText(!skipInvisible); | |||
htmlGen->setAllTextInvisible(allInvisible); | htmlGen->setAllTextInvisible(allInvisible); | |||
htmlGen->setEmbedBackgroundImage(embedBackground); | ||||
htmlGen->setExtractFontFiles(!noFonts); | htmlGen->setExtractFontFiles(!noFonts); | |||
htmlGen->setEmbedFonts(embedFonts); | ||||
htmlGen->setConvertFormFields(formFields); | ||||
htmlGen->startDoc(doc); | htmlGen->startDoc(doc); | |||
// convert the pages | // convert the pages | |||
for (pg = firstPage; pg <= lastPage; ++pg) { | for (pg = firstPage; pg <= lastPage; ++pg) { | |||
if (globalParams->getPrintStatusInfo()) { | ||||
fflush(stderr); | ||||
printf("[processing page %d]\n", pg); | ||||
fflush(stdout); | ||||
} | ||||
htmlFileName = GString::format("{0:s}/page{1:d}.html", htmlDir, pg); | htmlFileName = GString::format("{0:s}/page{1:d}.html", htmlDir, pg); | |||
pngFileName = GString::format("{0:s}/page{1:d}.png", htmlDir, pg); | pngFileName = GString::format("{0:s}/page{1:d}.png", htmlDir, pg); | |||
if (!(htmlFile = openFile(htmlFileName->getCString(), "wb"))) { | if (!(htmlFile = openFile(htmlFileName->getCString(), "wb"))) { | |||
error(errIO, -1, "Couldn't open HTML file '{0:t}'", htmlFileName); | error(errIO, -1, "Couldn't open HTML file '{0:t}'", htmlFileName); | |||
delete htmlFileName; | delete htmlFileName; | |||
delete pngFileName; | delete pngFileName; | |||
goto err2; | goto err2; | |||
} | } | |||
if (!(pngFile = openFile(pngFileName->getCString(), "wb"))) { | if (embedBackground) { | |||
error(errIO, -1, "Couldn't open PNG file '{0:t}'", pngFileName); | pngFile = NULL; | |||
fclose(htmlFile); | } else { | |||
delete htmlFileName; | if (!(pngFile = openFile(pngFileName->getCString(), "wb"))) { | |||
delete pngFileName; | error(errIO, -1, "Couldn't open PNG file '{0:t}'", pngFileName); | |||
goto err2; | fclose(htmlFile); | |||
delete htmlFileName; | ||||
delete pngFileName; | ||||
goto err2; | ||||
} | ||||
} | } | |||
pngURL = GString::format("page{0:d}.png", pg); | pngURL = GString::format("page{0:d}.png", pg); | |||
err = htmlGen->convertPage(pg, pngURL->getCString(), htmlDir, | err = htmlGen->convertPage(pg, pngURL->getCString(), htmlDir, | |||
&writeToFile, htmlFile, | &writeToFile, htmlFile, | |||
&writeToFile, pngFile); | &writeToFile, pngFile); | |||
delete pngURL; | delete pngURL; | |||
fclose(htmlFile); | fclose(htmlFile); | |||
fclose(pngFile); | if (!embedBackground) { | |||
fclose(pngFile); | ||||
} | ||||
delete htmlFileName; | delete htmlFileName; | |||
delete pngFileName; | delete pngFileName; | |||
if (err != errNone) { | if (err != errNone) { | |||
error(errIO, -1, "Error converting page {0:d}", pg); | error(errIO, -1, "Error converting page {0:d}", pg); | |||
exitCode = 2; | exitCode = 2; | |||
goto err2; | goto err2; | |||
} | } | |||
} | } | |||
// create the master index | // create the master index | |||
End of changes. 29 change blocks. | ||||
24 lines changed or deleted | 64 lines changed or added |