[poppler] HtmlOutputDev.cc patch: PPM images

Warren Toomey poppler at tuhs.org
Mon Sep 29 17:50:31 PDT 2008


The attached patch allows pdftohtml to output non DCT images from a PDF
document as PPM files. The program is still hard-coded to write image
hyperlinks as ".jpg". One possible fix would be to build a GooList of
created image filenames and use this list, but the attached patch does not
do this.

Cheers,
	Warren
-------------- next part --------------
*** HtmlOutputDev.cc	2008/09/30 00:18:37	1.1
--- HtmlOutputDev.cc	2008/09/30 00:44:06
***************
*** 743,748 ****
--- 743,750 ----
      fprintf(f,"<A name=%d></a>",pageNum);
      GooString* fName=basename(DocName); 
      for (int i=1;i<HtmlOutputDev::imgNum;i++)
+       // Not all output images are JPG. This needs to be extended to
+       // select the correct image suffix as required.
        fprintf(f,"<IMG src=\"%s-%d_%d.jpg\"><br>\n",fName->getCString(),pageNum,i);
      HtmlOutputDev::imgNum=1;
      delete fName;
***************
*** 1279,1286 ****
      delete imgnum;
    }
    else {
!     OutputDev::drawImage(state, ref, str, width, height, colorMap,
! 			 maskColors, inlineImg);
    }
  }
  
--- 1281,1331 ----
      delete imgnum;
    }
    else {
!     // Dump the image as a PPM file.
!     // This code taken from poppler/utils/ImageOutputDev.cc,
!     Guchar *p;
!     GfxRGB rgb;
! 
!     // Open the image file and write the PPM header
!     GooString *fName=new GooString(Docname);
!     fName->append("-");
!     GooString *pgNum= GooString::fromInt(pageNum);
!     GooString *imgnum= GooString::fromInt(imgNum);  
!     fName->append(pgNum)->append("_")->append(imgnum)->append(".ppm");
!     ++imgNum;
! 
!     if (!(f1 = fopen(fName->getCString(), "wb"))) {
!       error(-1, "Couldn't open image file '%s'", fName->getCString());
!       return;
!     }
!     fprintf(f1, "P6\n");
!     fprintf(f1, "%d %d\n", width, height);
!     fprintf(f1, "255\n");
! 
!     // initialize stream
!     ImageStream *imgStr = new ImageStream(str, width,
!                         colorMap->getNumPixelComps(), colorMap->getBits());
!     imgStr->reset();
! 
!     // for each line...
!     for (int y = 0; y < height; ++y) {
! 
!       // write the line
!       p = imgStr->getLine();
!       for (int x = 0; x < width; ++x) {
!         colorMap->getRGB(p, &rgb);
!         fputc(colToByte(rgb.r), f1);
!         fputc(colToByte(rgb.g), f1);
!         fputc(colToByte(rgb.b), f1);
!         p += colorMap->getNumPixelComps();
!       }
!     }
!     fclose(f1);
! 
!     delete fName;
!     delete pgNum;
!     delete imgnum;
!     delete imgStr;
    }
  }
  


More information about the poppler mailing list