1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
<%@ Page codepage="65001" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="Persits.PDF" %>
<script runat="server" LANGUAGE="VB">
Sub Page_Load(Source As Object, E As EventArgs)
If Not IsPostBack Then
Align.SelectedIndex = 0
End If
' to keep sessionID (used for file name generation) from changing every time
Session("dummy") = 1
End Sub
Public Sub GeneratePDF(Sender As Object, args As System.EventArgs)
' create instance of the PDF manager
Dim objPDF As PdfManager = New PdfManager()
' Create new document
Dim objDoc As PdfDocument = objPDF.CreateDocument()
' Add a page to document
Dim objPage As PdfPage = objDoc.Pages.Add()
' Arial font supports Latin, Greek, Cyrillic, Hebrew and Arabic
Dim objFont As PdfFont = objDoc.Fonts("Arial")
Dim strText As String = txtLargeText.Text
' Parameters: X, Y of upper-left corner of text box, Height, Width
Dim objParam As PdfParam = objPDF.CreateParam("x=100;y=742;height=692;width=412")
' Alignment and Arabic/Hebrew option
objParam("Alignment") = Single.Parse(Align.SelectedItem.Value)
Dim nReverse As Integer = 0
If chkReverse.Checked Then nReverse = 1
objParam("ReverseHebrewArabic") = nReverse
while strText.Length > 0
' DrawText returns the number of characters that fit in the box allocated.
Dim nCharsPrinted As Integer = objPage.Canvas.DrawText( strText, objParam, objFont )
' The entire string printed? Exit loop.
If nCharsPrinted = strText.Length Then Exit While
' Otherwise print remaining text on next page
objPage = objPage.NextPage
strText = strText.Substring( nCharsPrinted )
End While
' We use Session ID for file names.
' false means "do not overwrite"
' The method returns generated file name.
Dim strPath As String = Server.MapPath( "files") + "\\" + Session.SessionID + ".pdf"
Dim strFileName As String = objDoc.Save( strPath, False )
lblResult.Text = "Success. Your PDF file <font color=gray>" + strFileName + "</font> can be downloaded <A TARGET=_new HREF=""files/" + strFileName + """><B>here</B></A>."
End Sub
</script>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">
<TITLE>AspPDF Text Live Demo</TITLE>
</HEAD>
<BODY>
<BASEFONT FACE="Arial" SIZE="2">
<h3>AspPDF.NET Multi-language Support Demo</h3>
Type or copy/paste some text in any or all of the following alphabets:<BR>
<B>Latin, Hebrew, Cyrillic, Arabic, Greek</B>
<form name="frmText" runat="server">
<INPUT TYPE="Checkbox" ID="chkReverse" OnClick="if( this.checked ) this.form.Align[2].checked = true;" runat="Server"/>
Reverse letters (Hebrew and Arabic only)<BR>
<table Style="font-name: arial; font-size: 12;">
<tr><td>Alignment:</td><td>
<ASP:RadioButtonList id="Align" runat="server" RepeatDirection="Horizontal" Style="font-name: arial; font-size: 12;">
<ASP:ListItem Value="0">Left</ASP:ListItem>
<ASP:ListItem Value="2">Center</ASP:ListItem>
<ASP:ListItem Value="1">Right</ASP:ListItem>
</ASP:RadioButtonList></td></tr>
</table>
<BR>
<ASP:TextBox runat="Server" ID="txtLargeText" TextMode="1" Columns="80" Rows="16" runat="Server"/>
<BR>
<INPUT TYPE="SUBMIT" ID="btnSave" Value="Generate PDF" OnServerClick="GeneratePDF" runat="Server">
<P>
<B><ASP:Label ID="lblResult" runat="Server"/></B>
</form>
<B><A HREF="demo_text.zip">Download source code (C# and VB.NET) for this demo</A></B>
</BASEFONT>
</BODY>
</HTML> |
Partager