十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
利用DataWindow.net在 vb.net 下导出PDF格式文件
专注于为中小企业提供网站建设、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业湖北免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了成百上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
利用datawindow.net,导出PDF文件,实现前提:
1.安装Acrobat Distiller虚拟打印机,注意要用datawindow.net提供的打印驱动,在c:\program files\sybase\datawindow.net2.0\driver中,在文章最后,我会提供一个静态安装虚拟打印机的批处理文件,方便安装。
2.安装Ghostscript 7.05 ,在网上找,免费的。
3.导出PDF文件前,一要指定虚拟打印机名,其次导出格式为PDF(Export.PDF.Method=Distill!),另外还要指定 PDF.Distill.CustomPostScript=Yes。
具体代码如下:
''' summary
''' 导出文件
''' /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("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
4 批处理文件(实现静默安装)
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();
========================
这段代码不知道对你有没有用处,也是在网上看到的
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();
写
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();