利用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 批处理文件(实现静默安装)
执行步骤:打开一个dwg文件,用netload加载下面代码所在的.dll文件,再输入命令plottest,就得到输出结果(一个.pdf文件)。
要用到的参考:
AcDbMgd.dll;AcMgd.dll;AutoCAD 2010 Type Library;System.Windows.Forms; AutoCAD/ObjectDBX Common 18.0 Type Library.
VB.NET:
Imports System
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Autodesk.AutoCAD.Runtime.CommandMethod("Plottest") _
Public Sub PlotToPDF()
Dim activeDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim ThisDrawing As AcadDocument = CType(activeDoc.AcadDocument, AcadDocument)
Dim layout As AcadLayout = ThisDrawing.ActiveLayout
Dim MediaName As String = layout.CanonicalMediaName
If MediaName.Equals("") Then
activeDoc.Editor.WriteMessage("There is no media set for the active layout.")
Return
Else
activeDoc.Editor.WriteMessage(("The media for the active layout is: " + MediaName))
End If
Try
Dim oplot As AcadPlotConfiguration = ThisDrawing.PlotConfigurations.Add("PDF", layout.ModelType)
oplot.PaperUnits = AcPlotPaperUnits.acMillimeters
oplot.StyleSheet = "monochrome.ctb"
oplot.PlotWithPlotStyles = True
oplot.ConfigName = "DWG To PDF.pc3"
oplot.UseStandardScale = True
oplot.StandardScale = AcPlotScale.acScaleToFit
oplot.PlotType = AcPlotType.acExtents
oplot.CenterPlot = True
Dim oMediaNames As Object = layout.GetCanonicalMediaNames
Dim mediaNames As ArrayList = New ArrayList(CType(oMediaNames, String()))
For Each sName As String In mediaNames
If sName.Contains(MediaName) Then
oplot.CanonicalMediaName = sName
layout.CopyFrom(oplot)
layout.PlotRotation = AcPlotRotation.ac0degrees
layout.RefreshPlotDeviceInfo()
ThisDrawing.SetVariable("BACKGROUNDPLOT", 0)
ThisDrawing.Plot.QuietErrorMode = True
ThisDrawing.Plot.PlotToFile("c:/temp/d1.pdf", "DWG To PDF.pc3")
oplot.Delete()
oplot = Nothing
Return
End If
Next
Catch es As System.Exception
System.Windows.Forms.MessageBox.Show(es.ToString)
End Try
End Sub
1、首先你在网上下载word转换成PDF格式的软件,如我的是dopdf-v7,或者是wordtopdftool,
2、安装完成后,打开word文档点打印,选择安装的转换虚拟打印机打印,我的如下图所示
3、点击打印保存桌面即可
希望能帮到你,祝你工作愉快~如有需要软件请联系腾讯号378823078
我一般都用aspose.word.dll来完成
先把文本框类容和图片存到word里面,然后把word专程pdf
这种方法很灵活也很生动,比直接生成pdf好多了
给你的附件有vb.net的例子还有aspose.word的dll档案
例子是从官网下的,我就是用这些例子学的,很简单。现在我很多项目需要生成pdf都是用这个完成的。
利用AcroPDF打开并显示PDF文件。
注意:必须事先安装免费的 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)运行效果
举个例子:
先引入命名空间:
Imports
System.IOImports
System.Security.AccessControl
代码:
Dim
sec
As
DirectorySecurity
=
New
DirectorySecurityDim
rule
As
FileSystemAccessRule
=
New
FileSystemAccessRule("Administrator",
FileSystemRights.Delete,
AccessControlType.Allow)sec.AddAccessRule(rule)Directory.CreateDirectory("C:\test",
sec)
这段代码就是以
Administrator
帐户
在
C:\
创建
test
文件夹。