asp-classicfpdf

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.


Solution

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