开发者

asp fpdf trying to output a image assigned to a variable

开发者 https://www.devze.com 2023-01-03 13:58 出处:网络
this is the code i used to display image in the header. the problem i have is i want to use a variable for the image, when i put the variable name instead of the image name i get an error:

this is the code i used to display image in the header. the problem i have is i want to use a variable for the image, when i put the variable name instead of the image name i get an error:

Microsoft JScript runtime error '800a138f'

'undefined' is null or not an object

/EKtestdb/fpdf/fpdf/includes/Basics.asp, line 121

    this.Header=function Header() 
  { 
  this.SetY (10) 
  this.SetFont ("Times","",10) 
  //this.Cell (45,5, "HEADER", 0, 0, "L") 
  this.SetFont ("Times","b",14) 
  //this.Cell (190,5, this.title, 0, 0, "C") 
  this.Cell (190,20, 开发者_Python百科this.title, 0, 0) 
  this.SetFont ("Times","",10) 
  this.Image('logoSM1.jpg',165,3,33) 
  this.Image( techpic ,165,3,33)

this is the code for basics.asp line 121:

this.strrpos=function strrpos(s,ch){ 
 res = s.lastIndexOf(ch) 
 if (res>0-1){return res}else{return false} 
} 
this.strpos=function strpos(s,ch,start){ 
 if (arguments.length<3){start=0} 
 res = s.indexOf(ch,start); 
 if (res>-1){return res}else{return false} 
}

if you just want to display an image this line should work:

this.Image('logoSM1.jpg',165,3,33)

but for using a variable instead of image name can someone help with this?


I am updating my answer, because I didn't realize you are using both JScript and VBscript. You don't need to add the <%=%> because all your code is already in <%%> on the Jscript side.

I am not sure why you are getting the problem, but looking at the code you added I don't see a LoadModels(), which the documentation for fpdf says you need if you are using a vbscript page.

http://www.aspxnet.it/public/Default.asp?page=174&idp=62

Also I am not sure if it matters, but maybe you can add an opening and closing single quotation marks:

this.Image( "'" + techpic + "'" ,165,3,33);

I also noticed that none of the code under this.Header=function Header() contains semicolons after them, which is required for JSCript.


The problem I had was with the variable declaration I am not sure why but I had to declare the variable in the first section of the pdf.asp file to output a variable in the header. For ouputting in the footer this was not the case and I am still unsure why here is a sample of the fpdf.asp code:

this.Header=function Header()
        {
        this.SetY (10);
        this.SetFont ("Times","b",14);
        this.Cell (190,20, this.title, 0, 0);
        this.SetFont ("Times","",10);
        //this.Image('logoSM1.jpg',165,3,33);
        this.Image( techpic2 ,165,3,33);
        }
    this.Footer=function Footer()
        {
        this.SetY (-15)
        this.SetFont ("Times","i",10)
        this.Cell (190, 5, "", 0, 1)
        this.Cell (190, 0, "", 1, 1)
        this.Cell (45, 5, EmployeeName + " - " + EmployeeNo, 0, 0, "L")
        this.Cell (100, 5, this.PageNo() + "/{nb}", 0, 0, "C")
        this.Cell (45, 5, "", 0, 0, "R")            
        }

In the code above the footer will retrieve the value of EmployeeName and output correctly but in the header the value of techpic2 would not be retrieved. In the line above techpic2 the image was successfully displayed here is a sample of the pdf.asp code:

strSQL = "SELECT * FROM employee_course_vendortraining_view "  

objRS.Open strSQL, objConn

%>

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

<%

Set pdf=CreateJsObject("FPDF")

pdf.CreatePDF()

pdf.SetPath("fpdf/")

'------pdf.SetFont "Arial","",16

pdf.Open()

pdf.AddPage()


if (objRS.EOF) then

else

    Do Until objRS.EOF = True

    EmployeeNo = objRS("EmployeeNo")
    EmployeeName = objRS("EmployeeName")
     techpic2 = objRS("techpic2") 

Here the variables are all assigned the value from the recordset this was working for ouputting from the footer but would not work for the header. But once I declared and set the variables in the example below the header would output correctly:

strSQL = "SELECT * FROM employee_course_vendortraining_view "  

    objRS.Open strSQL, objConn
Dim EmployeeName
    EmployeeName = objRS("EmployeeName")
Dim techpic2
    techpic2 = objRS("techpic2")
    %>

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

    <%

    Set pdf=CreateJsObject("FPDF")

    pdf.CreatePDF()

    pdf.SetPath("fpdf/")

Why the footer could read the variable but not the header I am still not sure why but if anyone else is having problems maybe this will help.

0

精彩评论

暂无评论...
验证码 换一张
取 消