Creare un documento PDF con asp NET
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 *.aspx
CODICE:
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="ASPPDFLib" %>
<script runat="server" LANGUAGE="C#">
void Page_Load(Object Source, EventArgs E)
{
IPdfManager objPdf = new PdfManager();
// Create empty document
IPdfDocument objDoc = objPdf.CreateDocument(Missing.Value);
// Set various document properties
objDoc.Title = "Titolo documento creato con NET";
objDoc.Creator = "linkbruttocane";
// Add a new page
IPdfPage objPage = objDoc.Pages.Add(Missing.Value, Missing.Value, Missing.Value);
// Select one of the standard PDF fonts
IPdfFont objFont = objDoc.Fonts["Helvetica", Missing.Value];
// Param string
String strParams = "x=0; y=650; width=612; alignment=center; size=50";
// Draw text on page
objPage.Canvas.DrawText( "creato in NET!", strParams, objFont );
// Save document, the Save method returns generated file name
String strFilename = objDoc.Save( Server.MapPath("/public/helloNET.pdf"), false );
//String strFilename = objDoc.Save( "d:/inetpub/webs/nomedominiocom/public/helloNET.pdf", false );
lblResult.Text = "creato! scarica il tuo file <A HREF=/public/" + strFilename + ">qui</A>";
}
</script>
<HTML>
<HEAD>
<TITLE>Crea PDF con ASP NET </TITLE>
</HEAD>
<BODY>
<ASP:Label ID="lblResult" runat="server"/>
</BODY>
</HTML>
|