Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Generazione file PDF

  1. #1
    Utente di HTML.it L'avatar di Mizushi
    Registrato dal
    Aug 2005
    Messaggi
    1,125

    Generazione file PDF

    Ciao.

    Questo codice genera un file pdf tramite un eseguibile; il problema che il pdf stampa soltanto soltanto l'ultimo dei records presenti nella tabella e non tutti nonostante sia all'interno di un ciclo, potreste aiutarmi? Grazie!

    codice:
    <%
    
    Set conn = Server.CreateObject("ADODB.Connection")
    set rs = Server.CreateObject("ADODB.Recordset")
    Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & server.mappath("/mdb-database/dbx.mdb") & " ; Persist Security Info = False"
    
    CmdeHTMLDOC = chr(34)&"c:\HTMLDOC\htmldoc.exe" &_
    chr(34)& "  -t pdf --quiet "& _
    "  --webpage -f "
    
    Set FSO =   Server.CreateObject("Scripting.FileSystemObject") 
    name_fileHTML = "fichier.html"
    dir = Server.MapPath(name_fileHTML)
    
       strSql = "SELECT * FROM tabella"
       Set objRs = Server.CreateObject("ADODB.Recordset")
       objRs.Open strSql, Conn, 3, 3
    
    If Not objRs.EOF Then
    Do While Not objRs.EOF
    
    set inF = FSO.OpenTextFile(dir, 2, true) 
    inF.write "<html><body>" &_
              "<table border=""1"" width=""100%"">" &_
              "<tr>" &_
              "<th>ID</th>" &_
              "<th>IP</th>" &_
              "<th>NAME</th>" &_          
              "</tr>" &_
              "<tr>" &_
              "<td>"& objRs("ID") &"</td>" &_
              "<td>"& objRs("IP") &"</td>" &_
              "<td>"& objRs("NAME") &"</td>"
    inF.close
    
    objRs.MoveNext
    Loop
    End If
    
    set wshell = Server.CreateObject("wscript.shell")
    
    fic_html = dir
    fic_pdf = Server.MapPath("fichier_test.pdf")
    
    wpath = CmdeHTMLDOC &chr(34)& _
    fic_pdf &chr(34)&" "& chr(34)& fic_html &chr(34)
    
    wshell.Run wpath, SW_SHOWNORMAL, true
    
    Set wshell = nothing
    
    Response.write "<script>window.document.location.href='" & _
    	 	Server.MapPath("fichier_test.pdf") & _
    		"';</script>"
    		
    Response.Redirect Server.MapPath("fichier_test.pdf")
    	
    	             objRs.Close
    		Set objRs = Nothing
    		
    		Conn.Close
    		Set Conn = Nothing
    
    %>

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Prima del Loop devi mettere
    "<html><body>" &_
    "<table border=""1"" width=""100%"">" &_
    dentro al loop devi mettere righe e colonne;
    e fuori dal loop devi chiudere ciò che hai aperto prima del loop.

    Roby

  3. #3
    Utente di HTML.it L'avatar di Mizushi
    Registrato dal
    Aug 2005
    Messaggi
    1,125
    Grazie a te ho risolto.

    Posto il codice funzionante e personalizzato; chi vuole scaricare l'eseguibile può farlo da qui:

    http://www.stefan-rinke.de/articles/...ad/htmldoc.zip

    codice:
    <%
    
    Function RandomPW(myLength)
    	Const minLength = 6
    	Const maxLength = 20
    	
    	Dim X, Y, strPW
    	
    	If myLength = 0 Then
    		Randomize
    		myLength = Int((maxLength * Rnd) + minLength)
    	End If
    	
    	For X = 1 To myLength
    		Y = Int((3 * Rnd) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase
    		
    		Select Case Y
    			Case 1
    				Randomize
    				strPW = strPW & CHR(Int((9 * Rnd) + 48))
    			Case 2
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 65))
    			Case 3
    				Randomize
    				strPW = strPW & CHR(Int((25 * Rnd) + 97))
    		End Select
    	Next
    	
    	RandomPW = strPW
    End Function
    
    	strPSW = RandomPW(10)
    
    Set conn = Server.CreateObject("ADODB.Connection")
    set rs = Server.CreateObject("ADODB.Recordset")
    Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & server.mappath("/mdb-database/dbx.mdb") & " ; Persist Security Info = False"
    
    CmdeHTMLDOC = chr(34)&"d:\HTMLDOC\htmldoc.exe" &_
    chr(34)& "  -t pdf --quiet "& _
    "  --webpage -f "
    
    Set FSO =   Server.CreateObject("Scripting.FileSystemObject") 
    name_fileHTML = strPSW &".html"
    dir = Server.MapPath(name_fileHTML)
    
       strSql = "SELECT * FROM TABELLA ORDER BY NAME ASC"
       Set objRs = Server.CreateObject("ADODB.Recordset")
       objRs.Open strSql, Conn, 3, 3 
       
    If Not objRs.EOF Then
    
    set inF = FSO.OpenTextFile(dir, 2, true) 
    inF.write "<html><body>" &_
              "<table border=""1"" width=""100%"">" &_
              "<tr>" &_
              "<th>ID</th>" &_
              "<th>IP</th>" &_
              "<th>NAME</th>" &_          
              "</tr>"
              
    Do While Not objRs.EOF
    inF.write "<tr>" &_
              "<td>"& objRs("ID") &"</td>" &_
              "<td>"& objRs("IP") &"</td>" &_
              "<td>"& objRs("NAME") &"</td>"
    objRs.MoveNext
    Loop
    inF.close
    End If
    
    set wshell = Server.CreateObject("wscript.shell")
    
    fic_html = dir
    fic_pdf = Server.MapPath(strPSW &".pdf")
    fic_pdf2 = strPSW &".pdf"
    
    wpath = CmdeHTMLDOC &chr(34)& _
    fic_pdf &chr(34)&" "& chr(34)& fic_html &chr(34)
    
    wshell.Run wpath, SW_SHOWNORMAL, true
    
    Set wshell = nothing
    	
    	    objRs.Close
    		Set objRs = Nothing
    		
    		Conn.Close
    		Set Conn = Nothing
    		
    %>
    
    <script language="javascript">
      alert("Registrazione eseguita correttamente: <%=fic_pdf2%>.");
      window.location.href="http://localhost/public/<%=fic_pdf2%>";
    </script>

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Ma questo script che fa in pratica?

    Roby

  5. #5
    Utente di HTML.it L'avatar di Mizushi
    Registrato dal
    Aug 2005
    Messaggi
    1,125
    Originariamente inviato da Roby_72
    Ma questo script che fa in pratica?

    Roby
    E' uno script ASP che genera, tramite l'eseguibile htmldoc.exe, prima un file html e poi lo converte in formato PDF; è corredato di fonts e di PostScript File.

    Lo trovo meno complesso della pur rispettabilissima classe di BAOL74, l'inconveniente che se sei su un hosting che non permette l'aggiunta di componenti aggiuntivi non puoi utilizzarlo.

    Qui trovi tutta la documentazione:

    http://www.htmldoc.org/

    http://www.stefan-rinke.de/articles/...n/ch03s03.html


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.