JezB
JezB

Reputation: 528

Outputting Images in ASP FPDF problem

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.

Upvotes: 2

Views: 7116

Answers (7)

Kang Pree
Kang Pree

Reputation: 1

several times I studied fpdf.asp, and from my experiments, I found that fpdf really needs the x and y coordinates where the image is placed.

try adding pdf.SetXY 10, 10 or other numbers so that it becomes:

<!--#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.SetXY 10, 10
pdf.Image "invoiceheader.jpg"
pdf.Output ()
%>

(sorry I didn't know this was a 2010 question, hehehe)

Upvotes: 0

Lyna Amc
Lyna Amc

Reputation: 1

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

Upvotes: 0

AshRenj
AshRenj

Reputation: 21

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.

Upvotes: 2

Adam
Adam

Reputation: 11

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.

Upvotes: 1

Paul
Paul

Reputation: 56

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

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

Upvotes: 0

JezB
JezB

Reputation: 528

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

Upvotes: 0

Edelcom
Edelcom

Reputation: 5058

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

Upvotes: 1

Related Questions