>>>On Fri, Aug 13, 2010 at 5:29 PM, <[email protected]> wrote:
>>>> I wish if I had sufficient sparetime to replace the background
>>>> image part from Ghostscript to poppler, but now I don't have...
>>>>
>>>> Regards,
>>>> mpsuzuki
Attached is a preliminary patch to add "-usesplash"
option to pdftohtml, which creates background image
by SplashOutputDev.
To create background image without text object, it
adds a flag to ignore text objects in SplashOutputDev.
Further discussion is needed the background image
should ignore all text objects, or, graphically
modified text objects and the "text" drawn by Type3
fonts should be rendered.
Regards,
mpsuzuki
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -868,6 +868,7 @@ SplashOutputDev::SplashOutputDev(SplashColorMode colorModeA,
textClipPath = NULL;
haveCSPattern = gFalse;
transpGroupStack = NULL;
+ displayText = gTrue;
}
void SplashOutputDev::setupScreenParams(double hDPI, double vDPI) {
@@ -1602,6 +1603,11 @@ void SplashOutputDev::drawChar(GfxState *state, double x, double y,
SplashPath *path;
int render;
+ // XXX: more detailed classification is needed,
+ // e.g. glyph path work should be drawn.
+ if (!displayText)
+ return;
+
// check for invisible text -- this is used by Acrobat Capture
render = state->getRender();
if (render == 3) {
@@ -1915,6 +1921,9 @@ void SplashOutputDev::drawType3Glyph(T3FontCache *t3Font,
T3FontCacheTag * /*tag*/, Guchar *data) {
SplashGlyphBitmap glyph;
+ // XXX: displayText should control this ?
+ if (!displayText)
+ return;
glyph.x = -t3Font->glyphX;
glyph.y = -t3Font->glyphY;
glyph.w = t3Font->glyphW;
--- a/poppler/SplashOutputDev.h
+++ b/poppler/SplashOutputDev.h
@@ -225,6 +225,8 @@ public:
void setFreeTypeHinting(GBool enable);
+ void setDisplayText(GBool display) { displayText = display; }
+
private:
void setupScreenParams(double hDPI, double vDPI);
@@ -278,6 +280,8 @@ private:
SplashTransparencyGroup * // transparency group stack
transpGroupStack;
SplashBitmap *maskBitmap; // for image masks in pattern colorspace
+
+ GBool displayText; // displayText
};
#endif
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -45,6 +45,8 @@
#include "PDFDocFactory.h"
#include "HtmlOutputDev.h"
#include "PSOutputDev.h"
+#include "splash/SplashBitmap.h"
+#include "SplashOutputDev.h"
#include "GlobalParams.h"
#include "Error.h"
#include "DateInfo.h"
@@ -64,8 +66,10 @@ GBool complexMode=gFalse;
GBool ignore=gFalse;
//char extension[5]=".png";
double scale=1.5;
+int resolution=72;
GBool noframes=gFalse;
GBool stout=gFalse;
+GBool useSplash=gFalse;
GBool xml=gFalse;
static GBool errQuiet=gFalse;
static GBool noDrm=gFalse;
@@ -107,6 +111,10 @@ static const ArgDesc argDesc[] = {
"use standard output"},
{"-zoom", argFP, &scale, 0,
"zoom the pdf document (default 1.5)"},
+ {"-r", argInt, &resolution, 0,
+ "resolution to render the pdf document (default 72)"},
+ {"-splash", argFlag, &useSplash, 0,
+ "use SplashOutputDev to create background image"},
{"-xml", argFlag, &xml, 0,
"output for XML post-processing"},
{"-hidden", argFlag, &showHidden, 0,
@@ -134,9 +142,10 @@ 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;
+ GooString *psFileName = NULL;
PSOutputDev *psOut = NULL;
+ SplashOutputDev *splashOut = NULL;
GBool ok;
char *p;
char extension[16] = "png";
@@ -347,50 +356,76 @@ int main(int argc, char *argv[]) {
//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->getXRef(),
- doc->getCatalog(), 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 -r72 -sOutputFile=%s%%03d.png -g%dx%d -q %s", GHOSTSCRIPT, htmlFileName->getCString(), w, h,
- psFileName->getCString());*/
+ if (useSplash) {
+ SplashColor paperColor = { 255, 255, 255 };
+ splashOut = new SplashOutputDev(splashModeRGB8, 4, gFalse, paperColor);
+ splashOut->setDisplayText(gFalse);
+ splashOut->startDoc(doc->getXRef());
+
+ int page;
+ for (page=firstPage;page<=lastPage;page++)
+ {
+ doc->displayPageSlice(splashOut, page,
+ resolution, resolution,
+ 0,
+ gFalse, // useCropBox
+ gFalse,
+ gFalse,
+ 0, 0, w*scale*resolution/72.0, h*scale*resolution/72.0 );
+ GooString *imgFileName = new GooString(htmlFileName->getCString());
+ imgFileName->appendf("{0:03d}.png",page);
+ SplashBitmap *bitmap = splashOut->getBitmap();
+ bitmap->writeImgFile(splashFormatPng, imgFileName->getCString(), resolution, resolution);
+ delete imgFileName;
+ }
+ delete splashOut;
+ } else {
+ psFileName = new GooString(htmlFileName->getCString());
+ psFileName->append(".ps");
+
+ psOut = new PSOutputDev(psFileName->getCString(), doc->getXRef(),
+ doc->getCatalog(), 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(-1, "Failed to launch Ghostscript!\n");
+ 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>(resolution*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*resolution/72.0));
+ gsCmd->append(tw);
+ gsCmd->append("x");
+ th = GooString::fromInt(static_cast<int>(scale*h*resolution/72.0));
+ gsCmd->append(th);
+ gsCmd->append(" -q \"");
+ gsCmd->append(psFileName);
+ gsCmd->append("\"");
+// printf("running: %s\n", gsCmd->getCString());
+ if( !executeCommand(gsCmd->getCString()) && !errQuiet) {
+ error(-1, "Failed to launch Ghostscript!\n");
+ }
+ unlink(psFileName->getCString());
+ delete tw;
+ delete th;
+ delete sc;
+ delete gsCmd;
+ delete psFileName;
}
- unlink(psFileName->getCString());
- delete tw;
- delete th;
- delete sc;
- delete gsCmd;
- delete psFileName;
}
delete htmlOut;
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler