Avatar billede andersasp Nybegynder
21. november 2007 - 11:28 Der er 3 kommentarer

Kan ikke få en sub til at fungere

Hejsa eksperter,

Jeg laver i nedenstående script en PDF hvor jeg har to kolonner. Dog kan jeg ikke få mit:

Call GeneratePdf()  til at fungere???

Det skal lige siges at jeg har modificeret et fungerende script så det kan godt være der er noget helt galt.. men jeg er meget ny i Subs

Tror det er i denne funktion "Sub GeneratePdf()" men ved ikke hvor problemet er ???

Den fejl jeg får er "Object required: 'PdfPage' "  jeg har markeret linien med fejlen i scriptet forneden med ' ########

Håber der er nogle som kan hjælpe.

<!--#include file="../Connections/pdfdatabase.asp" -->
<%
'on error resume next

Dim Pdf
Dim Doc
Dim PdfPage
Dim PdfFont
Dim PdfBarcodeFont

Dim CurrYPos
Dim CurrPageNo

Set Pdf = Server.CreateObject("Persits.Pdf")
'Pdf.RegKey = "IWez+gzm9x8nIAcKfuBAC41g1Fp/aN+p8i0OGrbw8J1mVYKz9MyyaZgJiUzoRCwy4RbkYcSkyQE7"

Call GeneratePdf()

'-----------------------------------------------------------------------------------------------------------
'Build the PDF dynamically and send the Pdf content as the page response

'MmodelnrList =  a list of comma delimited Mmodelnr's

Sub GeneratePdf()

    Dim Counter
    Dim Conn
    Dim ConnStr
    Dim Sql
   
    'create the pdf document
    Set Doc = Pdf.CreateDocument

    'init document properties
    Doc.Title = "Pro Design Denmark"
    Doc.Creator = "Pro Design Denmark"
    Doc.CreationDate = Now
    Doc.Author = "Pro Design Denmark"

    'init the font to be used for text
    Set PdfFont = Doc.Fonts("Arial")

    'init the font to be used for text
    Set PdfBarcodeFont = Doc.Fonts.LoadFromFile(Server.MapPath(".") & "\V100020_.TTF")

    'open an ADO connection to the database
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open MM_pdfdatabase_STRING

    'create the recordset for the items query
    Dim Rs
    Set Rs = Server.CreateObject("ADODB.Recordset")

    'Items query
    Sql = "SELECT * from Booklettemple order by Tmodelnr ASC"

    Call Rs.Open(Sql, Conn, 3) 'adOpenStatic


    'loop thru all the items
    Counter = 0
    While Not Rs.EOF
        Counter = Counter + 1

    'handle page break
        'If PrevMmodelnr <> CurrMmodelnr Or Counter > 18 Then
        If Counter > 18 Then
            Set PdfPage = Doc.Pages.Add               
            PrevCounter = CurrCounter
            Counter = 1
        End If 
       
        If Counter Mod 2 <> 0 Then
            Call PrintItem(Rs, 1)
        Else
            Call PrintItem(Rs, 2)
        End If

        Rs.MoveNext
    Wend

    'clean up
    Rs.Close
    Conn.Close

    'save to HTTP stream
    Response.Buffer = True
    Response.Clear
    Call Doc.SaveHttp("attachment;filename=booklet.pdf")
    Response.End
End Sub

'-----------------------------------------------------------------------------------------------------------
'Print an individual item placed on the left or right column
Sub PrintItem(RS, Column)

    Dim XPos
    Dim YPos

    If Column = 1 Then Pos = 0.95 Else Pos = 5.25

    Call PdfPage.Canvas.DrawRect(X(Pos), Y(CurrYPos + 1.0), CPoints(1.9), CPoints(0.65)) ' ########
    Params = "x=" & CvStr(X(Pos + 0.30)) & ", y=" &  CvStr(Y(CurrYPos + 0.35)) & ", size=30, color=black"

    usethisbarcode    = Rs("Tbarcode")
    usethisbarcode    = "*"&usethisbarcode&"*"

    Call PdfPage.Canvas.DrawText(usethisbarcode, Params, PdfBarCodeFont)

    Params = "x=" & CvStr(X(Pos)) & ", y=" &  CvStr(Y(CurrYPos + 1.10)) & ", size=8, color=black"
    Call PdfPage.Canvas.DrawText(Rs("Tvariantnr"), Params, PdfFont)

    Params = "x=" & CvStr(X(Pos)) & ", y=" & CvStr(Y(CurrYPos + 1.23)) & ", size=8, color=black"
    Call PdfPage.Canvas.DrawText("Size: " & Rs("Tsize"), Params, PdfFont)

    If Column = 1 Then Pos = 2.86 Else Pos = 7.16

    thisisthecolor    = Rs("Tcolor")
        if thisisthecolor <> "" then
        thisisthecolor    = replace(thisisthecolor, " ", "")
        thisisthecolor    = "#" & thisisthecolor
        else
        thisisthecolor    = "#FFFFFF"
        end if

    if thisisthecolor = "#cludes" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#5,23e+059" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#5,7e+069" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#7,11e+021" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#5,04e+037" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#XXXXXX" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#7,9e+027" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#7e+037" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#5,32e+030" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#6,24e+028" then
    thisisthecolor    = "#FFFFFF"
    end if
   
    if thisisthecolor = "#7,74e+040" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#5,83e+043" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#6,52e+031" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#6,14e+049" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#6,24e+047" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#4,56e+079" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#5,73e+043" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#3,82e+039" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#75966-" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#8E4E1-" then
    thisisthecolor    = "#FFFFFF"
    end if

    if thisisthecolor = "#E4E4E-" then
    thisisthecolor    = "#FFFFFF"
    end if

'response.write Rs("vcolor") & " | "

    Call PdfPage.Canvas.SetParams("FillColor=" & thisisthecolor)
    Call PdfPage.Canvas.FillRect(X(Pos), Y(CurrYPos + 1.0), CPoints(0.50), CPoints(0.25))

    If Column = 2 Then
        CurrYPos = CurrYPos + 1.15
    End If
End Sub

'-----------------------------------------------------------------------------------------------------------
'AspPDF coordinates are always in points (72 points / inch) and the
'coordinate space has the origin in the lower-left corner of the page with the
'X axis extending horizontally to the right, and the Y axis vertically upwards.
'
'Points are not natural to work with so the following functions
'are simply helper functions to work in inches instead of points
'and from a top-bottom coordinate system.
'-----------------------------------------------------------------------------------------------------------

'-----------------------------------------------------------------------------------------------------------
'Y value in inches from top of page
Function Y(ByVal Inches)
    Y = CPoints(Round(11 - Inches, 4))
End Function

'-----------------------------------------------------------------------------------------------------------
'X value in inches from left of page
Function X(ByVal Inches)
    X = CPoints(Inches)
End Function

'-----------------------------------------------------------------------------------------------------------
'Converts inches to points (72 points / inch)
Function CPoints(ByVal Inches)
    CPoints = Inches * 72
End Function

'-----------------------------------------------------------------------------------------------------------
'Converts points to inches (72 points / inch)
Function CInches(ByVal Points)
    CInches = Points / 72
End Function

'-----------------------------------------------------------------------------------------------------------
'Converts a numeric value to a string with the correct decimal point
Function CvStr(ByVal Value)
    CvStr = Replace(Value, ",", ".")
End Function
%>
Avatar billede anri Novice
21. november 2007 - 13:53 #1
Så vidt jeg lige kan se, kommer der først noget i PdfPage hvis der er over 18 poster.
På en eller anden måde må du få PdfPage til at indeholde første side som default..  Måske gør denne linie det, men jeg kender ikke den komponent du bruger så jeg ved ikke om der som default er noget i  Doc.Pages(0);

Set PdfPage = Doc.Pages(0)
Avatar billede andersasp Nybegynder
21. november 2007 - 14:24 #2
Hejsa Tak for indslaget.. nu har jeg tilføjet følgende men den kommer med denne fejl??

        If Counter > 18 Then
            Set PdfPage = Doc.Pages.Add               
            PrevCounter = CurrCounter
            Counter = 1
        else
        Set PdfPage = Doc.Pages(0) ' < fejl her!!
        End If

Persits.PdfManager.1 error '800a0004'

Index out of range.
Avatar billede anri Novice
21. november 2007 - 17:27 #3
Hvilken komponent er det du bruger?

Kan det tænkes at du skal tilføje en side før du kan tilgå den ?


    Call Rs.Open(Sql, Conn, 3) 'adOpenStatic


    Set PdfPage = Doc.Pages.Add    ' Tilføjer den første side
    'loop thru all the items
    Counter = 0
    While Not Rs.EOF
        Counter = Counter + 1

    'handle page break
        'If PrevMmodelnr <> CurrMmodelnr Or Counter > 18 Then
        If Counter > 18 Then
            Set PdfPage = Doc.Pages.Add               
            PrevCounter = CurrCounter
            Counter = 1
        End If 
       
        If Counter Mod 2 <> 0 Then
            Call PrintItem(Rs, 1)
        Else
            Call PrintItem(Rs, 2)
        End If

        Rs.MoveNext
    Wend
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester