重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
利用AcroPDF打开并显示PDF文件。
创新互联公司主要从事成都网站建设、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务旬阳,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
注意:必须事先安装免费的 Adobe Reader 11.0
(1)创建一个VB6工程。在工具栏中点击鼠标右键,调出右键菜单--部件--Adobe Acrobat 7.0 Control Type Library 1.0--确定
(2)在Form1中布置一个AcroPDF控件
(3)窗体代码
Option Explicit
Private Sub Form_Load()
Me.Caption = "我的PDF阅读器"
' 加载PDF文档并显示
AcroPDF1.LoadFile ("D:\电子书籍\ProgrammingWpf.pdf")
End Sub
Private Sub Form_Resize()
'调整 AcroPDF1大小,占满整个窗口
AcroPDF1.Move 30, 30, ScaleWidth - 60, ScaleHeight - 60
End Sub
(4)运行效果
写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")
sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then
Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fm)
Do While sr.Peek() = 0
TextBox1.Text = sr.ReadLine() (读取文本到文本框)
Loop end if
利用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 批处理文件(实现静默安装)
'不就是打开PDF吗
下面是代码
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Dim Sfile as string
Dim lR As Long
sfile="文件路径"
lR = ShellExecute(Me.hWnd, "Open", sfile, "", "", vbNormalFocus)