让所有程序 都可以 自动化 以PdfReader 为例

介绍了一个使用VB.NET自定义程序配合PdfReader实现PDF文件批量转换为TXT文件的方法。该方案通过向PdfReader发送键盘指令来完成转换过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求:批量转化n多的pdf文件到txt文件,选择的工具是PdfReader,PdfReader不支持批量操作。

实现:通过自定义VB.NET程序向PdfReader程序发送键盘指令来实现批量转化,VB.NET测试代码粘贴如下:

        
        Try

            If String.IsNullOrEmpty(Me.txtPdfFilesFolder.Text) Or String.IsNullOrEmpty(Me.txtResultTxtFilesFolder.Text) Then

                MessageBox.Show("请选择pdf或txt文件夹路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop)

                Exit Sub
            End If

            Dim sourcePdfFolder As String = Me.txtPdfFilesFolder.Text.Trim()
            Dim targetTxtFolder As String = Me.txtResultTxtFilesFolder.Text.Trim()

            Dim exePath As String = Application.StartupPath + "/pdfreader/PdfReader.exe"
            Shell(exePath, AppWinStyle.NormalFocus)

            Dim intFileCount As Integer = 0
            Dim dir As New System.IO.DirectoryInfo(sourcePdfFolder)
            For Each file As System.IO.FileInfo In dir.GetFiles()
                If ".pdf".Equals(file.Extension.ToLower()) = True Then

                    Dim strPdfFileFullName As String = file.FullName
                    Dim strTxtFileFullName As String = targetTxtFolder + "/" + file.Name.Replace(file.Extension, "") + ".txt"

                    SendKeys.Send("%F^O")
                    SendKeys.Send(strPdfFileFullName)
                    SendKeys.Send("{ENTER}")


                    SendKeys.Send("^F4")

                    SendKeys.Send("%F{DOWN 5}")
                    SendKeys.Send("{ENTER}")
                    SendKeys.Send(strTxtFileFullName)
                    SendKeys.Send("{ENTER}")

                    intFileCount = intFileCount + 1

                End If
            Next

            SendKeys.Send("%F^X")

        Catch ex As Exception
            MessageBox.Show("转化出现错误:" + ex.Message, "错误")
        End Try

 

 

遗留的的小问题:因为是程序间直接发送键盘指令,可能受到中文输入法的影响,最好程序把输入法设置成英文。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值