在 ASP FPDF 中输出图像问题

发布于 2024-09-25 17:03:09 字数 497 浏览 0 评论 0原文

你好 我正在尝试使用 ASPFPDF 类使用下面非常简单的代码在 pdf 上输出图像:

<!--#include file="fpdf.asp"-->
<%
 Dim pages

 Dim pdf
 Set pdf=CreateJsObject("FPDF")

 pdf.CreatePDF "P", "mm", "A4"

 pdf.SetPath "fpdf/"

 pdf.Open()
 pdf.AddPage("P")

 pdf.Image "invoiceheader.jpg"
 pdf.Output ()
%>

运行时,此脚本应该打开 pdf,但使用 Adob​​e Reader 我收到一条“文件不以 %pdf 开头”消息。我尝试使用其他阅读器得到类似的结果。

如果我删除图像行并输出一些文本(例如 pdf.Cell 40,5,"Date",0,1,"R"),则一切正常。

在我发疯之前,任何人都有任何想法!

谢谢。

Hi
I'm attempting to use the ASPFPDF class to output an image on a pdf using the very simple code below:

<!--#include file="fpdf.asp"-->
<%
 Dim pages

 Dim pdf
 Set pdf=CreateJsObject("FPDF")

 pdf.CreatePDF "P", "mm", "A4"

 pdf.SetPath "fpdf/"

 pdf.Open()
 pdf.AddPage("P")

 pdf.Image "invoiceheader.jpg"
 pdf.Output ()
%>

When run, this script should open the pdf but with Adobe Reader I get a "File does not begin with %pdf" message. I've tried using other readers with similar results.

If I remove the image line and output some text (e.g. pdf.Cell 40,5,"Date",0,1,"R"), everything works perfectly.

Anyone got any ideas before I go mad!

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦里寻她 2024-10-02 17:03:09

尝试一下这里

pdf.Image "IMAGES/invoiceheader.jpg", 140, 22, 50, 40

140 是 x 位置,22 是 y 位置 50 是宽度,40是高度。

Try this one

pdf.Image "IMAGES/invoiceheader.jpg", 140, 22, 50, 40

Here 140 is the x position, 22 is the y-position 50 is the width and 40 is the height.

忱杏 2024-10-02 17:03:09

我不知道 AspFPdf,但是您不需要指定要在其中找到图像的文件夹吗?
你尝试了吗?

pdf.Image "fpdf/invoiceheader.jpg"

正如我所说,我不知道该组件,只是我的想法(尽管您可能自己尝试过)。

[编辑] 查看 Asp Fpdf 的网站并在文档中看到以下内容:

file 
Path or URL of the image. 

Asp fPdf :图像参数

无论如何:感谢您为我指明了该组件的方向(即使这不是您的意图)。我也可以用这个;-)

I don't know AspFPdf, but don't you need to specify a folder where the image is to be found ?
Did you try ?

pdf.Image "fpdf/invoiceheader.jpg"

As I said, I don't know the component, just my thoughts (although you have propably tried this yourself).

[EDIT] Look at the website of Asp Fpdf and saw the following in the documentation:

file 
Path or URL of the image. 

Asp fPdf : Image parameter

Anyway: thanks for pointing me in the direction of this component (even though this was not your intention). I can use this too ;-)

迷你仙 2024-10-02 17:03:09

只是想我应该向人们通报最新情况,因为我花了很长时间终于完成了这项工作。由于随机错误消息,您看不到的是 FPDF 应用程序在构建时创建了一个临时 PDF。默认情况下,它将在运行它的 asp 页面所在的同一文件夹中创建它。
例如,我的页面位于我的网站根目录 \createpdf.asp 中,

我发现它正在尝试在我的网站中创建一个名为 D10456.tmp 的文件(名称每次都会更改) root,但由于安全原因无法root。

我添加了一个输出文件名并更改了另一个文件夹中的安全性以允许写入访问,并且它第一次工作。

输出文件代码:

  pdf.Output server.mappath("pdfs\list.pdf"),"F"    

PDFS 文件夹必须具有写入权限才能工作。
希望能帮助人们。
Paul的回答对于在ASP中添加图像的格式也是正确的。
另外,我必须更改位于 include 目录中的 images.asp 文件。
我必须更改该行:

this.Buffer.LoadFromFile(Server.MapPath("\\") + ("\\") + ("Images") + ("\\") + pFileName);

因为

this.Buffer.LoadFromFile(Server.MapPath(pFileName));

它在错误的文件夹中查找我的图像。

Just thought I'd update people as I've spent ages and have finally got this working. What you don't see due to random error messages is that the FPDF application creates a temporary PDF as it's building it. By default, it will create it in the same folder as your asp page that runs it.
e.g. My page was in my web root \createpdf.asp

I worked out that it was trying to create a file called D10456.tmp (name changes each time) in my web root but it couldn't due to security.

I added an output file name and changed the security in another folder to allow write access and it worked first time.

Code for output file:

  pdf.Output server.mappath("pdfs\list.pdf"),"F"    

The PDFS folder must have write access to work.
Hope that helps people.
The answer by Paul is also correct for the format of adding an image in ASP.
Also, I had to change the images.asp file which is located in the includes directory.
I had to change the line:

this.Buffer.LoadFromFile(Server.MapPath("\\") + ("\\") + ("Images") + ("\\") + pFileName);

to

this.Buffer.LoadFromFile(Server.MapPath(pFileName));

because it was looking in the wrong folder for my images.

两仪 2024-10-02 17:03:09

上述问题的答案是,FPDF 似乎需要位于完全限定的域上 - 我在一台机器上运行,使用自定义主机文件将 URL 指向开发服务器。当我将代码移至实时服务器后,一切正常!

我不完全明白为什么,但这可能对其他人有帮助......

The answer to the above question is that the FPDF seems to need to be on a fully qualified domain - I was running on a machine with using a custom hosts file to point the URL at the development server. As soon as I moved the code to the live server, everything worked!

I don't fully understand why, but this might help someone else...

ι不睡觉的鱼゛ 2024-10-02 17:03:09

我发现添加图像的唯一方法如下:-

pdf.Image "./byimage.jpg",x,y,width

I found that the only way I could add images was as follows:-

pdf.Image "./byimage.jpg",x,y,width

小情绪 2024-10-02 17:03:09

这就是我如何在 ASP 经典页面中显示图像:

pdf.Image "fpdf/header.jpg", 10, 10,80,20, "jpg"

如果没有错误,这就是如何定义变量(纠正我)如果我错了):

pdf.image“folder/image.type”,x坐标,y坐标,img宽度,img高度,“图像类型”

希望有帮助。因为我花了很多天才找到如何在我的 ASP 经典页面中显示图像..

This is how i manage to display my image in ASP classic page:

pdf.Image "fpdf/header.jpg", 10, 10,80,20, "jpg"

if not mistakes, this is how to define the variables (correct me if i'm wrong):

pdf.image "folder/image.type", x-coordinate, y-coordinate, img width, img height, "image type"

hope it helps. because i've spent many days just to find how to display the image in my asp classic page..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文