[poppler] PNG images for pdftohtml: patch

Warren Toomey poppler at tuhs.org
Wed Oct 1 15:09:01 PDT 2008


On 1st October 2008, Albert Astals Cid wrote:
> Any reason why we need GooList * HtmlOutputDev::imgList instead of the old way 
> of dealing with filenames?

Yes. The old code simply kept a count of the number of images on each page.
Then it would loop re-creating the filenames, with a hard-coded "jpg" suffix.
The new code creates both "jpg" and "png" files, so we must build a list of
filenames and remove the hard-coded "jpg".

> i think you modified the header too, that's not in the diff.

Yes, mea culpa. Here is the change:

--- HtmlOutputDev.h     2008/09/30 00:18:37     1.1
+++ HtmlOutputDev.h     2008/10/01 01:48:47
@@ -301,6 +301,7 @@
   int maxPageWidth;
   int maxPageHeight;
   static int imgNum;
+  static GooList * HtmlOutputDev::imgList;
   GooString *Docname;
   GooString *docTitle;
   GooList *glMetaVars;

> +    for(int i = 0; i < HtmlOutputDev::imgList->getLength(); i++) {
> +      fName= (GooString *)HtmlOutputDev::imgList->del(0);
> +      fprintf(f,"<IMG src=\"%s\"><br>\n",fName->getCString());
> +      delete fName;
> +    }
> That's wrong, you'll never process the file with index 1; you either do not 
> increment i or do not remove things from the list, but if you do both, it 
> won't work.

You are right, I'm treating the list length as a constant in the loop condition
but it is ever-decreasing. This replacement fixes the problem:

--- HtmlOutputDev.cc    2008/10/01 05:23:48     1.8
+++ HtmlOutputDev.cc    2008/10/01 22:05:22
@@ -748,7 +748,9 @@
   {
     fprintf(f,"<A name=%d></a>",pageNum);
     GooString* fName;
-    for(int i = 0; i < HtmlOutputDev::imgList->getLength(); i++) {
+    // Loop over the list of image names on this page
+    int listlen= HtmlOutputDev::imgList->getLength();
+    for (int i = 0; i < listlen; i++) {
       fName= (GooString *)HtmlOutputDev::imgList->del(0);
       fprintf(f,"<IMG src=\"%s\"><br>\n",fName->getCString());
       delete fName;
 
> Is the PNG code by Guillaume Cottenceau GPLv2 or later compatible?

It came with an X11 license, so I guess that means yes.

> > The utils/Makefile will need to be patched to include -lpng, and the config
> > system tweaked to search for libpng and define ENABLE_LIBPNG if it exists.
> Any chance you can do that?

Sorry, I do not have any autoconf/automake expertise. I need some assistance
here.

Many thanks,
	Warren


More information about the poppler mailing list