使用Visual Basic控制PDF文件 [英] control a PDF file with Visual Basic

查看:103
本文介绍了使用Visual Basic控制PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我想在Visual Studio中创建简单的WPF VB应用程序来查找驱动器中的PDF文件读取PDF格式的字段值。运行应用程序并根据字段值PDF表单创建消息。怎么做?

I would like to create simple WPF VB application in Visual Studio to find PDF file in drive and read fields value of PDF form. Run application and based on fields value PDF form create message. How to do it?

谢谢。

推荐答案

虽然可能涉及wpf,但大多数情况都不是wpf特定的。

Although wpf might be involved in this, most of how you'd do it is not wpf specific.

要从pdf中读取字段,请查看itextsharp:

To read fields from a pdf, take a look at itextsharp:

http://www.c-sharpcorner.com/article/fill-in-pdf-form- fields-using-the-open-source-itextsharp-dll /

http://www.c-sharpcorner.com/article/fill-in-pdf-form-fields-using-the-open-source-itextsharp-dll/

一个片段(如果你不跟随,可以使用在线转换器vb)

A snippet ( you could use an online converter to vb if you don't follow )

string pdfTemplate = "my.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
AcroFields fields = pdfReader.AcroFields.Fields;
string val = fields.GetField("fieldname");

要选择文件,请使用openfiledialog:

To pick the file, use an openfiledialog:

http://www.wpf-tutorial.com/dialogs/the-openfiledialog/

http://www.wpf-tutorial.com/dialogs/the-openfiledialog/

using System;
using System.IO;
using System.Windows;
using Microsoft.Win32;

namespace WpfTutorialSamples.Dialogs
{
        public partial class OpenFileDialogSample : Window
        {
                public OpenFileDialogSample()
                {
                        InitializeComponent();
                }

                private void btnOpenFile_Click(object sender, RoutedEventArgs e)
                {
                        OpenFileDialog openFileDialog = new OpenFileDialog();
                        if(openFileDialog.ShowDialog() == true)
                                txtEditor.Text = File.ReadAllText(openFileDialog.FileName);
                }
        }
}

您可以指定初始目录并过滤文件。

You can specify an initial directory and filter for files.

                     OpenFileDialog dlg = new OpenFileDialog();
                     dlg.InitialDirectory = Path.Combine(App.CurrentScenario.GeneralStaffFolder, "Maps");
                     dlg.Filter = "Map files(*.map) | *.map";
                     if (dlg.ShowDialog() == true)
                     {
                         string filename = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName);
                         MapFile = filename;
                     }

显然,你需要更少的.map而不是更多的.pdf,并且可能有一些不同的方式来指定基础文件夹。

Obviously, you'll want rather less .map and rather more .pdf and presumably some different way to specify a base folder.

我猜你在驱动器的任何地方都没有任何字面意思,因为搜索整个驱动​​器通常需要一段时间,因此需要考虑更具体的内容。

I guess you don't literally mean any pdf anywhere in a drive and have something more specific in mind since searching an entire drive would usually take a while.


这篇关于使用Visual Basic控制PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆