Search code examples
javascriptpdfvbscriptasp-classicfpdf

FPDF not showing more than one image


Below is a little snippet which works fine, it shows me a PDF file, but with only the last image I set.

What is wrong in my code? I didn't found documentation for ASP FPDF, only for PHP. Any help is apreciated. Thanks!

<%@language=vbscript%>
<!--#include file="fpdf.asp"-->
<%Response.ContentType="application/pdf"%>

<%
imgCat = "..\fc_img\cat.jpg"
imgDog = "..\fc_img\dog.jpg"
Set pdf=CreateJsObject("FPDF")
pdf.CreatePDF "L", "mm", "A4"
pdf.SetPath("fpdf/")
pdf.Open()

pdf.AddPage()

pdf.SetTitle "Life is a b1tch"
pdf.Image imgDog , 10, 10, 20, 20
pdf.Image imgCat , 40, 40, 20, 20

pdf.Close()
pdf.Output()
%>

Solution

  • After researching this a bit, I've come to the conclusion that the ASP component version of FPDF has a bug that is causing this behaviour.

    There is a interesting thread on FPDF Library - PDF Generator site forum - [ASP] Pb avec PDF de 2 pages which describes your exact problem and conclusion they come to is the ASP version of the FPDF component has a bug that is causing the issue.

    Perhaps if you show us your fpdf.asp include file we might be able to help more, as the OP in the thread mentioned

    "I solved it. I don't know how, but I solved it."

    suggests it is possible to fix.


    Edit:

    I think this maybe the what you are using ASP FPDF which is over 10+ years old and doesn't seem to be maintained.

    /****************************************************************************
    *                                                                           *
    * Software              : FPDF for Asp                                      *
    * Version               : 1.01 beta                                         *
    * Date                  : 2003/11/15                                        *
    * Author                : Lorenzo Abbati                                    *
    * License               : Freeware                                          *
    * Site                  : http://www.aspxnet.it                             *
    *                                                                           *
    *****************************************************************************
    *                                                                           *
    * Author (PHP Class)    : Olivier Plathey                                   *
    * Site (PHP Class)      : http://www.fpdf.org                               *
    *                                                                           *
    *****************************************************************************
    *                                                                           *
    * You may use and modify this software as you wish.                         *
    *                                                                           *
    ****************************************************************************/
    

    Latest download seems to be v1.01

    The referenced website http://www.aspxnet.it doesn't seem to have anything useful.


    In the past when it comes to Classic ASP I've found AspPDF by Persits Software inc to be invaluable when building PDFs dynamically. It isn't free like ASP FPDF but it does work and is constantly updated and supported. Might be worth a look rather then trying to dig through the fpdf.asp to find the cause of the .Image bug.


    Update:

    Think the issue is with the this._out and the way the buffer is built, as this would explain why the one image is outputted and the other one isn't. For example if the buffer get's reset. Unfortunately the only way to work this out is to dig through the source code.

    this.Image=function Image(xfile , xx , xy , xw , xh , xtype , xlink)
    {
      if (arguments.length<5){xh=0};
      if (arguments.length<6){xtype=""};
      if (arguments.length<7){xlink=""};
    
      if(!lib.isset(this.images[xfile]))
      {
        if(xtype=="")
        {
          xpos=lib.strrpos(xfile,".");
          if(!xpos)this.Error("Image file has no extension and no type was specified: " + xfile);
          xtype=lib.substr(xfile,xpos+1);
        }
        xtype=xtype.toLowerCase();
        if(xtype=="jpg" || xtype=="jpeg") xinfo=this._parsejpg(xfile);
        else this.Error("Unsupported image file type: " + xtype);
    
        xinfo["i"]=lib.count(this.images)+1;
        this.images[xfile]=xinfo;
      }
      else
        xinfo=this.images[xfile];
    
      if(xw==0)xw=xh*xinfo["w"]/xinfo["h"];
      if(xh==0)xh=xw*xinfo["h"]/xinfo["w"];
    
      this._out(lib.sprintf("q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q",xw*this.k,xh*this.k,xx*this.k,(this.h-(xy+xh))*this.k,xinfo["i"]));
      if(xlink)this.Link(xx,xy,xw,xh,xlink);
    }