Generare PDF da codice HTML contenuto in file di testo [*.TXT] attraverso asp
nota bene: lo script nella versione "copia e incolla" che segue, presuppone permessi di scrittura lato server .. in paritcolare, è la root o cartella di destinazione del nuovo documento PDF che deve possedere i permessi di scrittura [chmod "666" - "777"] ..e l' utilizzo è di assoluta facilità: copia inclolla e salva come *.asp
RICHIEDE FILE TXT
CODICE:
<%
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
' Small pages - to demonstrate text spanning
Set page = Doc.Pages.Add( 300, 300 )
' Use Arial font
Set Font = Doc.Fonts("Arial")
' Load string from file
Text = Pdf.LoadTextFromFile(Server.MapPath("html.txt") )
' Parameters: X, Y of upper-left corner of text box, Height, Width, HTML=true
Set param = pdf.CreateParam("x=10; y=290; width=280; height=280; html=true")
Do While Len(Text) > 0
CharsPrinted = Page.Canvas.DrawText(Text, param, Font )
' Save HTML tag generated by DrawText to reflect current font state
HtmlTag = Page.Canvas.HtmlTag
' We printed the entire string. Exit loop.
if CharsPrinted = Len(Text) Then Exit Do
' Otherwise print remaining text on next page
Set Page = Page.NextPage
Text = HtmlTag & Right( Text, Len(Text) - CharsPrinted)
Loop
' Save document, the Save method returns generated file name
Filename = Doc.Save( Server.MapPath("/public/html-asp.pdf"), False )
Response.Write "fatto!, file pdf generato da html, scarica <A HREF=/public/" & Filename & ">qui</A>"
%>
|