2016-04-22 68 views
0

我正在使用Neodynamic SDK將文檔打印到客戶端。使用不同的按鈕打印不同的文檔

我們將打印5份文件。我看到如何打印1個文檔或打印所有文檔,但有沒有辦法打印每個按鈕1個文檔。即BUTTON1打印出DOC1,BUTTON2打印DOC2等

這裏是我有這麼遠

<script runat="server"> 

     Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) 
      fileone() 
      filetwo() 

     End Sub 

     Public Sub fileone() 
      Dim fileToPrint As New PrintFile(Context.Server.MapPath("~/forms/xmlheader.txt"), "xmlheader.txt") 
      If (WebClientPrint.ProcessPrintJob(Request)) Then 

       'Create a ClientPrintJob 
       Dim cpj As New ClientPrintJob() 
       'set client printer, for multiple files use DefaultPrinter... 
       cpj.ClientPrinter = New DefaultPrinter() 
       'set files-printers group by using special formatting!!! 
       'Invoice.doc PRINT TO Printer1 
       cpj.PrintFile = fileToPrint 
       'send it... 
       cpj.SendToClient(Response) 
      End If 
     End Sub 
     Public Sub filetwo() 
      Dim fileToPrint As New PrintFile(Context.Server.MapPath("~/forms/ How To Recover Office Doc.pdf"), " How To Recover Office Doc.pdf") 
      If (WebClientPrint.ProcessPrintJob(Request)) Then 

       'Create a ClientPrintJob 
       Dim cpj As New ClientPrintJob() 
       'set client printer, for multiple files use DefaultPrinter... 
       cpj.ClientPrinter = New DefaultPrinter() 
       'set files-printers group by using special formatting!!! 
       'Invoice.doc PRINT TO Printer1 
       cpj.PrintFile = fileToPrint 
       'send it... 
       cpj.SendToClient(Response) 
      End If 
     End Sub 



     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
      fileone() 
      ScriptManager.RegisterStartupScript(Me, Me.GetType(), "printForm1", "printForm1();", True) 
     End Sub 

     Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
      filetwo() 
      ScriptManager.RegisterStartupScript(Me, Me.GetType(), "printForm2", "printForm2();", True) 
     End Sub 
</script> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
<title>How to print multiple files to client printers from ASP.NET</title> 
<script type="text/javascript"> 
    function printForm1() { 
     jsWebClientPrint.print(fileone()); 
    } 
    function printForm2() { 
     jsWebClientPrint.print(filetwo()); 
    } 
</script> 
</head> 
<body> 
<%-- Store User's SessionId --%> 
<input type="hidden" id="sid" name="sid" value="<%=Session.SessionID%>" /> 

<form id="form1" runat="server"> 

<h1>How to print multiple files to client printers from ASP.NET</h1> 
Please change the source code to match your printer names and files to test it locally 
<br /><br /> 
&nbsp;<%-- Add Reference to jQuery at Google CDN --%><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script><%-- Register the WebClientPrint script code --%><%=Neodynamic.SDK.Web.WebClientPrint.CreateScript()%>&nbsp;&nbsp;&nbsp;&nbsp; 
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" 
    Height="156px" Width="156px" /> 
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" Height="156px" Width="156px"/> 
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Button" 
    Height="156px" Width="156px"/> 
<asp:Button ID="Button4" runat="server" onclick="Button4_Click" Text="Button" 
    Height="156px" Width="156px"/> 
<asp:Button ID="Button5" runat="server" onclick="Button5_Click" Text="Button" 
    Height="156px" Width="156px"/> 
    </form> 

</body> 
</html> 

我想改變FileTwo傳送()變量clientprintjob cpj2的...

+0

當您考慮將filetwo()變量更改爲clientprintjob cpj2時發生了什麼? – Mogsdad

+0

打印出來的兩個相同的文件 –

回答

0

什麼您需要創建一個名爲PrintDoc()的函數,該函數接收要作爲參數打印的文件的路徑。簽名應該是這樣的:

Private Sub PrintDoc(path as String) 

End Sub 

你只需要這個功能,一次不需要子fileone()和子FileTwo傳送()...高達filefive()。然後,您需要5個按鈕,每個按鈕都有自己的_Click()事件,並且在該事件處理程序中,您每次都通過傳遞不同的參數來調用PrintDoc過程。

希望這會有所幫助。

祝你好運!

+0

似乎只在page_init()時打印,當我創建子文件時它永遠不會激發webclientprint.processprintjob(請求) –

+0

我得到錯誤PrintJob內容無效。打印作業進程被取消 –