【问题标题】:FPDF not showing more than one imageFPDF 不显示超过一张图像
【发布时间】:2024-01-18 23:46:01
【问题描述】:

下面是一个运行良好的小 sn-p,它显示了一个 PDF 文件,但只有我设置的最后一张图像。

我的代码有什么问题? 我没有找到 ASP FPDF 的文档,仅适用于 PHP。 任何帮助都将不胜感激。谢谢!

<%@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()
%>

【问题讨论】:

  • 如果你在 Image 调用之间调用 AddPage,你会得到两个图像吗?
  • @safetyOtter,我在每个页面中都有一个图像,因为 AddPage 添加了另一个页面

标签: javascript pdf vbscript asp-classic fpdf


【解决方案1】:

经过一番研究,我得出的结论是,FPDF 的 ASP 组件版本存在导致此行为的错误。

FPDF Library - PDF Generator 网站论坛上有一个有趣的帖子 - [ASP] Pb avec PDF de 2 pages 描述了您的确切问题,他们得出的结论是 FPDF 组件的 ASP 版本存在导致问题的错误。

也许如果您向我们展示您的 fpdf.asp 包含文件,我们可能会提供更多帮助,作为线程中提到的 OP

“我解决了。我不知道怎么解决的,但我解决了。”

建议可以修复。


编辑:

我认为这可能是您使用的 ASP FPDF 已有 10 多年的历史并且似乎没有得到维护。

/****************************************************************************
*                                                                           *
* 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.                         *
*                                                                           *
****************************************************************************/

最新下载好像是v1.01

引用的网站http://www.aspxnet.it似乎没什么用处。


过去,当谈到经典 ASP 时,我发现 AspPDF by Persits Software inc 在动态构建 PDF 时非常有用。它不像 ASP FPDF 那样免费,但它确实可以工作,并且会不断更新和支持。可能值得一看,而不是尝试挖掘 fpdf.asp 以找到 .Image 错误的原因。


更新:

认为问题出在this._out 和缓冲区的构建方式上,因为这可以解释为什么输出一张图像而没有输出另一张图像。例如,如果缓冲区被重置。不幸的是,解决这个问题的唯一方法是挖掘源代码。

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);
}

【讨论】:

  • 我不再关心这个问题了,但如果有一天我回到它,我会试试这个。谢谢