[PATCH] pdftohtml: remove use of gs for rendering pages

Adrian Johnson ajohnson at redneon.com
Fri Apr 20 03:10:04 PDT 2012


---
 goo/gfile.cc       |    8 ----
 goo/gfile.h        |    3 --
 utils/pdftohtml.cc |  124 +++++++++++-----------------------------------------
 3 files changed, 26 insertions(+), 109 deletions(-)

diff --git a/goo/gfile.cc b/goo/gfile.cc
index 7522424..7833502 100644
--- a/goo/gfile.cc
+++ b/goo/gfile.cc
@@ -545,14 +545,6 @@ GBool openTempFile(GooString **name, FILE **f, const char *mode) {
 #endif
 }
 
-GBool executeCommand(char *cmd) {
-#ifdef VMS
-  return system(cmd) ? gTrue : gFalse;
-#else
-  return system(cmd) ? gFalse : gTrue;
-#endif
-}
-
 #ifdef WIN32
 GooString *fileNameToUTF8(char *path) {
   GooString *s;
diff --git a/goo/gfile.h b/goo/gfile.h
index d4b9082..34b85f0 100644
--- a/goo/gfile.h
+++ b/goo/gfile.h
@@ -104,9 +104,6 @@ extern time_t getModTime(char *fileName);
 // should be "w" or "wb".  Returns true on success.
 extern GBool openTempFile(GooString **name, FILE **f, const char *mode);
 
-// Execute <command>.  Returns true on success.
-extern GBool executeCommand(char *cmd);
-
 #ifdef WIN32
 // Convert a file name from Latin-1 to UTF-8.
 extern GooString *fileNameToUTF8(char *path);
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index d6475b0..a4b2eb6 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -75,7 +75,6 @@ GBool printHtml = gFalse;
 GBool complexMode=gFalse;
 GBool singleHtml=gFalse; // singleHtml
 GBool ignore=gFalse;
-static GBool useSplash=gTrue;
 static char extension[5]="png";
 static double scale=1.5;
 GBool noframes=gFalse;
@@ -89,7 +88,6 @@ GBool showHidden = gFalse;
 GBool noMerge = gFalse;
 static char ownerPassword[33] = "";
 static char userPassword[33] = "";
-static char gsDevice[33] = "none";
 static GBool printVersion = gFalse;
 
 static GooString* getInfoString(Dict *infoDict, const char *key);
@@ -132,8 +130,6 @@ static const ArgDesc argDesc[] = {
    "do not merge paragraphs"},   
   {"-enc",    argString,   textEncName,    sizeof(textEncName),
    "output text encoding name"},
-  {"-dev",    argString,   gsDevice,       sizeof(gsDevice),
-   "output device name for Ghostscript (png16m, jpeg etc)"},
   {"-fmt",    argString,   extension,      sizeof(extension),
    "image file format for Splash output (png or jpg)"},
   {"-v",      argFlag,     &printVersion,  0,
@@ -181,18 +177,15 @@ int main(int argc, char *argv[]) {
   GooString *docTitle = NULL;
   GooString *author = NULL, *keywords = NULL, *subject = NULL, *date = NULL;
   GooString *htmlFileName = NULL;
-  GooString *psFileName = NULL;
   HtmlOutputDev *htmlOut = NULL;
 #ifdef HAVE_SPLASH
   SplashOutputDev *splashOut = NULL;
 #endif
-  PSOutputDev *psOut = NULL;
   GBool doOutline;
   GBool ok;
   char *p;
   GooString *ownerPW, *userPW;
   Object info;
-  const char * extsList[] = {"png", "jpeg", "bmp", "pcx", "tiff", "pbm", NULL};
 
   // parse args
   ok = parseArgs(argDesc, &argc, argv);
@@ -344,19 +337,6 @@ int main(int argc, char *argv[]) {
   info.free();
   if( !docTitle ) docTitle = new GooString(htmlFileName);
 
-  if( strcmp("none", gsDevice) ) {
-    useSplash = gFalse;
-    /* determine extensions of output background images */
-    int i;
-    for(i = 0; extsList[i]; i++)
-    {
-      if( strstr(gsDevice, extsList[i]) != (char *) NULL )
-      {
-        strncpy(extension, extsList[i], sizeof(extension));
-        break;
-      }
-    }
-  }
 
 #ifndef HAVE_SPLASH
   if( useSplash ) {
@@ -421,87 +401,35 @@ int main(int argc, char *argv[]) {
   }
   
   if ((complexMode || singleHtml) && !xml && !ignore) {
-    if(useSplash) {
 #ifdef HAVE_SPLASH
-      GooString *imgFileName = NULL;
-      // White paper color
-      SplashColor color;
-      color[0] = color[1] = color[2] = 255;
-      // If the user specified "jpg" use JPEG, otherwise PNG
-      SplashImageFileFormat format = strcmp(extension, "jpg") ?
-          splashFormatPng : splashFormatJpeg;
-
-      splashOut = new SplashOutputDevNoText(splashModeRGB8, 4, gFalse, color);
-      splashOut->startDoc(doc);
-
-      for (int pg = firstPage; pg <= lastPage; ++pg) {
-        doc->displayPage(splashOut, pg,
-                         72 * scale, 72 * scale,
-                         0, gTrue, gFalse, gFalse);
-        SplashBitmap *bitmap = splashOut->getBitmap();
-
-        imgFileName = GooString::format("{0:s}{1:03d}.{2:s}", 
-            htmlFileName->getCString(), pg, extension);
-
-        bitmap->writeImgFile(format, imgFileName->getCString(),
-                             72 * scale, 72 * scale);
-
-        delete imgFileName;
-      }
+    GooString *imgFileName = NULL;
+    // White paper color
+    SplashColor color;
+    color[0] = color[1] = color[2] = 255;
+    // If the user specified "jpg" use JPEG, otherwise PNG
+    SplashImageFileFormat format = strcmp(extension, "jpg") ?
+      splashFormatPng : splashFormatJpeg;
+
+    splashOut = new SplashOutputDevNoText(splashModeRGB8, 4, gFalse, color);
+    splashOut->startDoc(doc);
+
+    for (int pg = firstPage; pg <= lastPage; ++pg) {
+      doc->displayPage(splashOut, pg,
+                       72 * scale, 72 * scale,
+                       0, gTrue, gFalse, gFalse);
+      SplashBitmap *bitmap = splashOut->getBitmap();
+
+      imgFileName = GooString::format("{0:s}{1:03d}.{2:s}", 
+                                      htmlFileName->getCString(), pg, extension);
+
+      bitmap->writeImgFile(format, imgFileName->getCString(),
+                           72 * scale, 72 * scale);
+
+      delete imgFileName;
+    }
 
-      delete splashOut;
+    delete splashOut;
 #endif
-    } else {
-      int h=xoutRound(htmlOut->getPageHeight()/scale);
-      int w=xoutRound(htmlOut->getPageWidth()/scale);
-      //int h=xoutRound(doc->getPageHeight(1)/scale);
-      //int w=xoutRound(doc->getPageWidth(1)/scale);
-
-      psFileName = new GooString(htmlFileName->getCString());
-      psFileName->append(".ps");
-
-      psOut = new PSOutputDev(psFileName->getCString(), doc,
-          NULL, firstPage, lastPage, psModePS, w, h);
-      psOut->setDisplayText(gFalse);
-      doc->displayPages(psOut, firstPage, lastPage, 72, 72, 0,
-          gTrue, gFalse, gFalse);
-      delete psOut;
-
-      /*sprintf(buf, "%s -sDEVICE=png16m -dBATCH -dNOPROMPT -dNOPAUSE -r%d -sOutputFile=%s%%03d.png -g%dx%d -q %s", GHOSTSCRIPT, resolution, htmlFileName->getCString(), w, h,
-      psFileName->getCString());*/
-
-      GooString *gsCmd = new GooString(GHOSTSCRIPT);
-      GooString *tw, *th, *sc;
-      gsCmd->append(" -sDEVICE=");
-      gsCmd->append(gsDevice);
-      gsCmd->append(" -dBATCH -dNOPROMPT -dNOPAUSE -r");
-      sc = GooString::fromInt(static_cast<int>(72*scale));
-      gsCmd->append(sc);
-      gsCmd->append(" -sOutputFile=");
-      gsCmd->append("\"");
-      gsCmd->append(htmlFileName);
-      gsCmd->append("%03d.");
-      gsCmd->append(extension);
-      gsCmd->append("\" -g");
-      tw = GooString::fromInt(static_cast<int>(scale*w));
-      gsCmd->append(tw);
-      gsCmd->append("x");
-      th = GooString::fromInt(static_cast<int>(scale*h));
-      gsCmd->append(th);
-      gsCmd->append(" -q \"");
-      gsCmd->append(psFileName);
-      gsCmd->append("\"");
-      //    printf("running: %s\n", gsCmd->getCString());
-      if( !executeCommand(gsCmd->getCString()) && !errQuiet) {
-        error(errIO, -1, "Failed to launch Ghostscript!\n");
-      }
-      unlink(psFileName->getCString());
-      delete tw;
-      delete th;
-      delete sc;
-      delete gsCmd;
-      delete psFileName;
-    }
   }
   
   delete htmlOut;
-- 
1.7.9.5


--------------000800030404000301080506--


More information about the poppler mailing list