Creare un documento PDF da form con 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
CODICE:
<form action="testo.asp" METHOD="POST">
<B>Inserisci il testo:</B><BR>
<textarea name="largetext" cols="80" rows="16"><% = Request("largetext") %>
</textarea><BR>
<INPUT TYPE="submit" name="Save" Value="Genera PDF">
</form>
<%
if Request("Save") <> "" Then
Set Pdf = Server.CreateObject("Persits.Pdf")
Set Doc = Pdf.CreateDocument
' Small pages - to demonstrate text spanning
Set page = Doc.Pages.Add( 216, 216 )
' Use Times-Roman font
Set Font = Doc.Fonts("Times-Roman")
Text = Request("largetext")
' Parameters: X, Y of upper-left corner of text box, Height, Width
Set param = pdf.CreateParam("x=10;y=206;height=196;width=196; size=7;HTML=True")
Do While Len(Text) > 0
CharsPrinted = Page.Canvas.DrawText(Text, param, Font )
' 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 = Right( Text, Len(Text) - CharsPrinted)
Loop
' Save document, the Save method returns generated file name
Filename = Doc.Save( Server.MapPath("/public/testo-asp.pdf"), False )
Response.Write "Fatto, scarica il file <A HREF=/public/" & Filename & ">qui</A>"
End If
%>
|