asppdf 加入中文

<%@ CodePage="65001" %>


<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">
<TITLE>AspPDF cjk Live Demo</TITLE>
</HEAD>
<BODY>

<TABLE WIDTH="640"><TR><TD>
<FONT FACE="Arial" SIZE="2">

<h3>AspPDF CJK Language Support Demo</h3> 
<form action="demo_cjk.asp" METHOD="POST" NAME="MyForm">
Enter document title: <INPUT TYPE="TEXT"NAME="Title" SIZE="40" VALUE="<% = Request("Title") %>"><P>
Type or copy/paste some text in <B>Chinese/Japanese/Korean</B> (CJK) characters:<BR>
<textarea name="largetext" cols="80" rows="16"><% = Request("largetext") %>
</textarea><BR>
<INPUT TYPE="submit" name="Save" Value="Generate PDF">
</form>

<%
	if Request("Save") <> "" Then

		Set Pdf = Server.CreateObject("Persits.Pdf")

		Set Doc = Pdf.CreateDocument

		' Set title
		Doc.Title = Request("Title")

		Set page = Doc.Pages.Add
    
		' Use an external file with the SimHei font supporting CJK alphabet
		Set font = Doc.Fonts.LoadFromFile( Server.MapPath("simhei.ttf") )

		Text	 = Request("largetext")
		
		' Parameters: X, Y of upper-left corner of text box, Height, Width
		Set param = pdf.CreateParam("x=100;y=742;height=692;width=412; spacing=2")
	    
		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

		' We use Session ID for file names
		' false means "do not overwrite"
		' The method returns generated file name
		Path = Server.MapPath( "files") & "\" & Session.SessionID & ".pdf"
		FileName = Doc.Save( Path, false)

		Response.Write "<P><B>Success. Your PDF file <font color=gray>" & FileName & "</font> can be downloaded <A HREF=""files/" & FileName & """><B>here</B></A></B>."
		Set Page = Nothing
		Set Doc = Nothing
		Set Pdf = Nothing

	End If
%>

<P>
<B><A HREF="demo_cjk.zip">Download source code (ASP and ASP.NET/C#) for this demo</A></B>

</FONT>
</TD></TR></TABLE>

</BODY>
</HTML>

该目录下放入 simhei.ttf  就可以实现中文的pdf文件





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lyflcear

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值