台灣最具影響力的-資訊專家社群 - 讓您成為最有價值的IT專業人才
線上人數
650
 
會員總數:230673
接案會員:6774
文章總數:2320
討論主題:176451
歡迎您免費加入會員
討論區列表 >> ASP.NET >> 如何將Word轉成PDF檔

[變換順序]
[我要回覆]
1


回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
如何將Word轉成PDF檔
價值 : 50 QP  點閱數:2500 回應數:1

點圖分享到Plurk吧!
樓主

vivi
門外漢
0 24
365 33
發送站內信

各位大大
我要把Word轉成PDF檔遇到一些問題
希望各位幫我看一下,謝謝^^

我有2台主機
A主機程式user填好表單,將參數傳到B主機套word文件轉成PDF檔
A主機程式我用 form 傳..B主機都接收不到參數
A主機程式用 Response.Redirect 傳..B主機就可接收
因為我要傳的參數很多...所以不適合用Response.Redirect傳
有別的方法嗎???

還有在B主機套word文件轉成PDF檔,如何讓PDF檔自動關閉??

A主機程式
<pre lang="aspx.vb">
<%@ Page Language="VB" %>
<%@ Import Namespace="aaa.Utility" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Dim name As String
Dim CUSTID As String
Dim CNV_Code As String

name = "tteesstt"
CUSTID = "A111111113"

Dim oHTTP As New aaa.Utility.HttpRequest
Dim Temp As String
CNV_Code = "Open_Account_By_Mail"

Temp = oHTTP.HttpRequest("http://B主機IP/Test.aspx")

' Response.Redirect("/TEST/" & Temp)
%>
<form method="post" name="frmLogonForm" action="1.asp" target=_blank>
<input type="hidden" name="name" value="<%=name%>">
<input type="hidden" name="temp" value="/TEST/<%=Temp%>">
</form>
<Script Language=JavaScript>
document.frmLogonForm.submit();
</Script>
</pre>

B主機程式
<pre lang="aspx.vb">
Imports System.IO

Partial Class test
Inherits System.Web.UI.Page

'// 來源檔名
Dim Source_File_Name As String
'// 來源檔(含路徑)
Dim Source_File As String
'// 欲複製的來源檔(含路徑)
Dim Source_Temp_File As String
'// 產生之PDF檔名(含路徑)
Dim Target_PDF_File As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'// 格式轉換代碼
Dim CNV_Code As String
'// 本次文件的 GUID
Dim PDF_GUID As String
'// 轉換種類
Dim CNV_Type As String
'// 來源檔(含路徑)
Source_File = Application("Source_Path")
'// 欲複製的來源檔(含路徑)
Source_Temp_File = Application("Source_Temp_Path")
'// 產生之PDF檔名(含路徑)
Target_PDF_File = Application("Target_PDF_Path")

Dim Temp As String

'// 產生本次的 GUID
PDF_GUID = System.Guid.NewGuid().ToString

'// 按收 Post 值
'// CNV_Code = Request("CNV_Code")
CNV_Code = Request("CNV_Code")

'// 先進入判斷
Select Case CNV_Code
Case "Open_Account'
CNV_Type = "DOCX_2_PDF"
Source_File_Name = "表單.docx"
Case Else
End Select

Select Case CNV_Type
Case "DOCX_2_PDF"
'// 開始轉換
Temp = fn_DOCX_2_PDF(Source_File_Name, PDF_GUID, CNV_Code)
Response.Write(Temp)
Case "XLSX2PDF"
Case Else
End Select
End Sub

Private Function fn_DOCX_2_PDF(ByVal xSource_File_Name As String, ByVal xPDF_GUID As String, ByVal xCNV_Code As String) As String
'// Word 轉 PDF

Dim xPDF As String

Source_File = Source_File & xSource_File_Name
Source_Temp_File = Source_Temp_File & "QQ-" & xPDF_GUID & "-" & xSource_File_Name
xPDF = "QQ-pdf-" & xPDF_GUID & ".pdf"
Target_PDF_File = Target_PDF_File & xPDF

'// 產生來源複製檔
File.Copy(Source_File, Source_Temp_File)

'// 開始轉換
Dim wdFormatPDF As Integer = 17 ' PDF format.
Dim wdFormatXPS As Integer = 18 ' XPS format.

Dim fso ' As FileSystemObject
Dim wdo ' As Word.Application
Dim wdoc ' As Word.Document
Dim wdocs ' As Word.Documents

wdo = Server.CreateObject("Word.Application")
wdocs = wdo.Documents


'// 開啟 Word 檔
wdoc = wdocs.Open(Source_Temp_File)

'// 用書籤方式填入值
'// 以不同 CNV_Code 區別要處理的項目
Select Case xCNV_Code
Case "Open_Account"
wdoc.Bookmarks("AccNo").Range.Text = "0000"
wdoc.Bookmarks("CID").Range.Text = "xxxxxxx"
wdoc.Bookmarks("Name_1").Range.Text = Request("name")
wdoc.Bookmarks("Name_2").Range.Text = Request("name")
wdoc.Bookmarks("Name_test").Range.Text = "123"
Case "其它"
wdoc.Bookmarks("AccNo").Range.Text = Request.Form("dd1")
wdoc.Bookmarks("CID").Range.Text = Request.Form("dd2")
wdoc.Bookmarks("Name_1").Range.Text = Request.Form("dd3")
Case Else
End Select

wdoc.SaveAs(Target_PDF_File, wdFormatPDF)

wdoc.Close(0)
wdo.Quit()
wdo = Nothing

Return xPDF
End Function
End Class


</pre>

本篇文章發表於2010-04-20 16:07
什麼是iT Power資訊報 新手會員瞧一瞧
1樓
最有價值解答

水月
檢舉此回應
建議大大可以去看這網頁:http://www.builder.com.cn/2007/1107/614526.shtml



本篇文章回覆於2010-05-03 09:28
--未登入的會員無法查看對方簽名檔--
[變換順序]
1
 

回覆
如要回應,請先登入.