Reputation: 101
I've been stuck on this problem for a while, done lots of searches and tried various solutions that others reported to be working, and yet I'm still stuck. So any suggestion is hugely appreciated. Please let me know if I'm being unclear. Many thanks in advance!!
I'm trying to generate a PDF in Classic ASP (I know....) with FPDF v.1.01 (available from http://www.aspxnet.it/public/Default.asp?page=172). But I keep getting a message "File does not begin with '%PDF-'" when the PDF is populated. I've tried this in Firefox 7.0.1, IE9, which are the two browsers we use at work. If I remove this line from the code, then everything works as expected. So all I know is this line is the trouble maker (maybe?)
this.Image('bg_logo_small.jpg',10,8,213,46);
I have a file named report.asp. The organization of the files looks like this:
./rpt/report.asp
./rpt/fpdf.asp
./rpt/bg_logo_small.jpg
./rpt/fpdf/ - this directory contains all the files extracted from fpdf1.01.zip
./rpt/fpdf/extends/
./rpt/fpdf/fonts/
./rpt/fpdf/includes/
./rpt/fpdf/models/
and report.asp looks like this,which is pretty much taken directly from the example on aspxnet.it site, except that I'm using my own jpg:
<%@LANGUAGE="javascript" CODEPAGE="65001"%>
<!--#include file="fpdf.asp" -->
<%
var pdf=new FPDF();
pdf.Header=function Header()
{
this.Image('bg_logo_small.jpg',10,8,213,46);
this.SetFont('Arial','B',15);
this.Cell(80);
this.Cell(30,10,'Title',1,0,'C');
this.Ln(20);
}
pdf.Footer=function Footer()
{
this.SetY(-15);
this.SetFont('Arial','I',8);
this.Cell(0,10,'Page '+ this.PageNo()+ '/{nb}',0,0,'C');
}
pdf.CreatePDF();
pdf.SetPath("fpdf/");
pdf.SetFont("Arial","",16);
pdf.Open();
pdf.AddPage();
pdf.Cell(40,10,"Hello Word!");
pdf.Close();
pdf.Output();
%>
I've tried the same thing in VBScript with
pdf.LoadModels("bgimg")
and function Header() and function Footer() placed in bgimg.mod, which was saved in
./rpt/fpdf/models/
The code above is all report.asp contains - no HTML inside.
Upvotes: 0
Views: 3070
Reputation: 11
I am not sure, if you haven't solved the problem yet, but anyway I answer, because it could help to somebody else.
I had the same problem and I was browsing and looking long long time for solution.
Finally I found the solution. Go in fpdf.asp file, look for line with code:
xfile=Server.MapPath(lib.fso.GetTempName())
You can change the code e.g. like this:
xfile=Server.MapPath("Temp/"+lib.fso.GetTempName())
where "Temp/" is name of folder where temporary file during PDF file generation will be created and later deleted. The main trick is to assign "Modify" access rights to the folder Temp.
The error "File does not begin with '%PDF-'" appear because there are no access rights to create and then delete temporary files for your final PDF file. So you have an option to assign "Modify" access right to your root folder or transfer temporary files for PDF in folder Temp and assign "Modify" only to folder Temp (this is more secure).
Upvotes: 1
Reputation: 1242
try with <%@LANGUAGE="javascript" %>
insted of <%@LANGUAGE="javascript" CODEPAGE="65001"%>
Just need to remove CODEPAGE="65001"
Upvotes: 0