利用DataWindow.net在 vb.net 下導(dǎo)出PDF格式文件
專(zhuān)注于為中小企業(yè)提供網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)湖北免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了成百上千企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
利用datawindow.net,導(dǎo)出PDF文件,實(shí)現(xiàn)前提:
1.安裝Acrobat Distiller虛擬打印機(jī),注意要用datawindow.net提供的打印驅(qū)動(dòng),在c:\program files\sybase\datawindow.net2.0\driver中,在文章最后,我會(huì)提供一個(gè)靜態(tài)安裝虛擬打印機(jī)的批處理文件,方便安裝。
2.安裝Ghostscript 7.05 ,在網(wǎng)上找,免費(fèi)的。
3.導(dǎo)出PDF文件前,一要指定虛擬打印機(jī)名,其次導(dǎo)出格式為PDF(Export.PDF.Method=Distill!),另外還要指定 PDF.Distill.CustomPostScript=Yes。
具體代碼如下:
''' summary
''' 導(dǎo)出文件
''' /summary
''' param name="sender"/param
''' param name="e"/param
''' remarks/remarks
Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Try
Dim strFilename, strPrinter As String
Dim saveDg As New SaveFileDialog
strPrinter = Me.dwPrint.Describe("DataWindow.Print.PrinterName")
saveDg.FileName = Me.dwPrint.Tag.ToString
saveDg.Filter = "Pdf文件|*.pdf|Excel文件|*.xls|所有文件|*.*"
If saveDg.ShowDialog = Windows.Forms.DialogResult.OK Then
strFilename = saveDg.FileName
If strFilename.IndexOf(".pdf") 0 Then
Me.dwPrint.Modify("DataWindow.Print.PrinterName='Acrobat Distiller'")
Me.dwPrint.Modify("DataWindow.Export.PDF.Method=Distill!")
Me.dwPrint.Modify("DataWindow.Export.PDF.Distill.CustomPostScript=Yes")
Me.dwPrint.SaveAs(strFilename, Sybase.DataWindow.FileSaveAsType.Pdf, True)
ElseIf strFilename.IndexOf(".xls") 0 Then
Me.dwPrint.SaveAs(strFilename, Sybase.DataWindow.FileSaveAsType.Excel, True)
End If
Me.dwPrint.Modify("DataWindow.Print.PrinterName='" + strPrinter + "'")
MessageBox.Show("導(dǎo)出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
4 批處理文件(實(shí)現(xiàn)靜默安裝)
FileStream ReadPdf = new FileStream("d:\\books\\vb.net\\OReilly's Visual Basic .NET Language in a Nutshell.pdf", FileMode.Open);
long FileSize;
FileSize = ReadPdf.Length;
byte[] Buffer = new byte[(int)FileSize];
ReadPdf.Read(Buffer, 0, (int)ReadPdf.Length);
ReadPdf.Close();
寫(xiě)
FileStream CreatePdf = new FileStream("d:\\books\\vb.net\\kotla.pdf", FileMode.Create);
CreatePdf.Write(Buffer,0,Buffer.Length);
CreatePdf.Close();
========================
這段代碼不知道對(duì)你有沒(méi)有用處,也是在網(wǎng)上看到的
FileStream ReadPdf = new FileStream(@"d:\books\vb.net\test.pdf", FileMode.Open);
long FileSize;
FileSize = ReadPdf.Length;
byte[] Buffer = new byte[(int)FileSize];
ReadPdf.Read(Buffer, 0, (int)ReadPdf.Length);
ReadPdf.Close();
寫(xiě)
FileStream CreatePdf = new FileStream(@"d:\books\vb.net\test1.pdf", FileMode.Create);
CreatePdf.Write(Buffer,0,Buffer.Length);
CreatePdf.Close();
希望能幫帶你的忙~告一段落~謝謝~
FileStream ReadPdf = new FileStream("d:\\books\\vb.net\\OReilly's Visual Basic .NET Language in a Nutshell.pdf", FileMode.Open);
long FileSize;
FileSize = ReadPdf.Length;
byte[] Buffer = new byte[(int)FileSize];
ReadPdf.Read(Buffer, 0, (int)ReadPdf.Length);
ReadPdf.Close();
д
FileStream CreatePdf = new FileStream("d:\\books\\vb.net\\kotla.pdf", FileMode.Create);
CreatePdf.Write(Buffer,0,Buffer.Length);
CreatePdf.Close();