pdf文件显示水印 vb_使用VB.NET显示PDF

pdf文件显示水印 vb

PDF files have an internal document format that requires a software object that "understands" the format. Since many of you might have used the functions of Office in your VB code, let's look briefly at Microsoft Word as an example of processing a formatted document to make sure we understand the concept. If you want to work with a Word document, you have to add a Reference to the Microsoft Word 12.0 Object Library (for Word 2007) and then instantiate the Word Application object in your code.

PDF文件具有内部文档格式,该格式需要“理解”该格式的软件对象。 由于你们中的许多人可能已经在VB代码中使用了Office的功能,因此让我们简要地看一下Microsoft Word,作为处理格式化文档以确保我们理解该概念的示例。 如果要使用Word文档,则必须添加对Microsoft Word 12.0对象库的引用(对于Word 2007),然后在代码中实例化Word Application对象。


Dim myWord As Microsoft.Office.Interop.Word.ApplicationClass
'Start Word and open the document.
myWord = CreateObject("Word.Application")
myWord.Visible = True
myWord.Documents.Open("C:\myWordDocument.docx")

("" must be replaced with the actual path to the document to make this code work on your PC.)

(“”必须替换为文档的实际路径,以使此代码在您的PC上正常工作。)

Microsoft uses the Word Object Library to provide other methods and properties for your use. Read the article COM -.NET Interoperability in Visual Basic to understand more about Office COM interop.

Microsoft使用Word对象库提供其他方法和属性供您使用。 阅读Visual Basic中的COM -.NET互操作性文章以了解有关Office COM互操作的更多信息。

But PDF files aren't a Microsoft technology. PDF - Portable Document Format - is a file format created by Adobe Systems for document exchange. For years, it was totally proprietary and you had to get software that could process a PDF file from Adobe. On July 1, 2008, PDF was finalized as a published international standard. Now, anyone is permitted to create applications that can read and write PDF files without having to pay royalties to Adobe Systems. If you plan on selling your software, you still may be required to get a license, but Adobe provides them royalty-free. (Microsoft created a different format called XPS that is based on XML. Adobe's PDF format is based on Postscript. XPS became a published international standard on June 16, 2009.)

但是PDF文件不是Microsoft的技术。 PDF-便携式文档格式-是Adobe Systems创建的用于文档交换的文件格式。 多年来,它是完全专有的,您必须从Adobe获得可以处理PDF文件的软件。 PDF在2008年7月1日最终定稿为已发布的国际标准。 现在,任何人都可以创建可以读写PDF文件的应用程序,而不必向Adobe Systems支付版权费。 如果您打算出售软件,可能仍需要获得许可,但Adobe免费提供它们。 (Microsoft创建了另一种称为XPS的格式,该格式基于XML。Adobe的PDF格式基于Postscript。XPS于2009年6月16日成为已发布的国际标准。)

PDF的用途 ( The Uses of PDF )

Since the PDF format is a competitor to Microsoft's technology, they don't provide a lot of support and you have to get a software object that "understands" the PDF format from someone other than Microsoft right now. Adobe returns the favor. They don't support Microsoft technology all that well either. Quoting from the latest (October 2009) Adobe Acrobat 9.1 documentation, "There is currently no support for the development of plug-ins using managed languages such as C# or VB.NET." (A "plug-in" is an on-demand software component. Adobe's plug-in is used to display PDF's in a browser.")

由于PDF格式是Microsoft技术的竞争对手,因此它们没有提供很多支持,您现在必须从Microsoft以外的其他人那里获得“理解” PDF格式的软件对象。 Adobe表示支持。 他们也不完全支持Microsoft技术。 引用最新的Adobe Acrobat 9.1文档(2009年10月),“目前不支持使用托管语言(例如C#或VB.NET)开发插件。” (“插件”是按需软件组件。Adobe的插件用于在浏览器中显示PDF。”)

Since PDF is a standard, several companies have developed software for sale that you can add to your project that will do the job, including Adobe. There are also a number of open-source systems available. You could also use the Word (or Visio) object libraries to read and write PDF files but using these large systems for just this one thing will require extra programming, also has license issues, and will make your program bigger than it has to be.

由于PDF是标准,因此包括Adobe在内的多家公司已经开发了可出售的软件,可以将其添加到可以完成此工作的项目中。 也有许多可用的开源系统。 您还可以使用Word(或Visio)对象库读取和写入PDF文件,但是仅将这些大型系统用于一件事将需要额外的编程,还存在许可证问题,并使您的程序比实际需要的更大。

Just as you need to buy Office before you can take advantage of Word, you also have to buy the full version of Acrobat before you can take advantage of more than just the Reader. You would use the full Acrobat product in about the same way that other object libraries, like Word 2007 above, are used. I don't happen to have the full Acrobat product installed so I couldn't provide any tested examples here.

就像您需要购买Office才能利用Word一样,您还必须购买完整版本的Acrobat,然后才能充分利用Reader以外的其他功能。 使用完整的Acrobat产品的方式与使用其他对象库(如上述Word 2007)的方式大致相同。 我碰巧没有安装完整的Acrobat产品,因此在这里无法提供任何经过测试的示例。

如何 ( How To )

But if you only need to display PDF files in your program, Adobe provides an ActiveX COM control that you can add to the VB.NET Toolbox. It will do the job for free. It's the same one you probably use to display PDF files anyway: the free Adobe Acrobat PDF Reader.

但是,如果只需要在程序中显示PDF文件,则Adobe提供了一个ActiveX COM控件,您可以将其添加到VB.NET工具箱中。 它将免费完成这项工作。 无论如何,您可能都会用它来显示PDF文件:免费的Adobe Acrobat PDF Reader。

To use the Reader control, first make sure that you have downloaded and installed the free Acrobat Reader from Adobe.

要使用Reader控件,首先请确保您已经从Adobe下载并安装了免费的Acrobat Reader。

Step 2 is to add the control to the VB.NET Toolbox. Open VB.NET and start a standard Windows application. (Microsoft's "next generation" of presentation, WPF, doesn't work with this control yet. Sorry!) To do that, right-click on any tab (such as "Common Controls") and select "Choose Items ..." from the context menu that pops up. Select the "COM Components" tab and click the checkbox beside "Adobe PDF Reader" and click OK. You should be able to scroll down to the "Controls" tab in the Toolbox and see the "Adobe PDF Reader" there.

步骤2是将控件添加到VB.NET工具箱。 打开VB.NET并启动标准Windows应用程序。 (Microsoft的演示文稿的“下一代” WPF尚不适用于此控件。很抱歉!)为此,右键单击任何选项卡(例如“ Common Controls”),然后选择“ Choose Items ...”。从弹出的上下文菜单中。 选择“ COM组件”选项卡,然后单击“ Adob​​e PDF Reader”旁边的复选框,然后单击“确定”。 您应该能够向下滚动到工具箱中的“控件”选项卡,然后在其中看到“ Adob​​e PDF Reader”。

Now just drag the control to your Windows Form in the design window and size it appropriately. For this quick example, I'm not going to add any other logic, but the control has lots of flexibility that I'll tell you how to find out about later. For this example, I'm just going to load a simple PDF that I created in Word 2007. To do that, add this code to the form Load event procedure:

现在,只需将控件拖到设计窗口中的Windows窗体中,并适当调整其大小即可。 对于这个快速的示例,我不会添加任何其他逻辑,但是控件具有很大的灵活性,稍后我将告诉您如何查找。 对于此示例,我将加载一个在Word 2007中创建的简单PDF。为此,请将以下代码添加到表单Load事件过程中:


Console.WriteLine(AxAcroPDF1.LoadFile( _
   "C:\Users\Temp\SamplePDF.pdf"))

Substitute the path and file name of a PDF file on your own computer to run this code. I displayed the result of the call in the Output windows only to show how that works. Here's the result:

用您自己的计算机上的PDF文件的路径和文件名代替以运行此代码。 我在“输出”窗口中显示了调用结果,只是为了展示其工作原理。 结果如下:

--------Click Here to display the illustrationClick the Back button on your browser to return--------

--------单击此处以显示插图单击浏览器上的“后退”按钮以返回--------

If you want to control the Reader, there are methods and properties for that in the control too. But the good folks at Adobe have done a better job than I could. Download the Adobe Acrobat SDK from their developer center (http://www.adobe.com/devnet/acrobat/). The AcrobatActiveXVB program in the VBSamples directory of the SDK shows you how to navigate in a document, get the version numbers of the Adobe software you are using, and much more. If you don't have the full Acrobat system installed - which must be purchased from Adobe - you won't be able to run other examples.

如果要控制Reader,控件中也有一些方法和属性。 但是Adobe的好人做得比我更好。 从其开发人员中心(http://www.adobe.com/devnet/acrobat/)下载Adobe Acrobat SDK。 SDK的VBSamples目录中的AcrobatActiveXVB程序向您显示如何导航文档,获取正在使用的Adobe软件的版本号等。 如果您没有安装完整的Acrobat系统(必须从Adobe购买),则将无法运行其他示例。

翻译自: https://www.thoughtco.com/display-a-pdf-with-vbnet-3424227

pdf文件显示水印 vb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值