专栏首页VB小源码[实用]VB.NET PDF文件批量打印

[实用]VB.NET PDF文件批量打印

VB.NET PDF文件批量打印,可以指定打印的页面,倒叙打印,顺序打印!方便快捷!


Imports Spire.License Imports Spire.Pdf Imports System.Drawing.Printing Imports System.IO

Public Class pdf_print Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load get_pt() End Sub Sub PT_PDF() On Error Resume Next If pd_file() = False Then Exit Sub Dim pdf_page As Integer = 0 Dim path As String Dim pdf As New PdfDocument For Each file_name In txt_coding.Lines If file_name <> “” Then path = txt_path.Text & file_name & “.pdf” If cb_all.Checked = True Then pdf_page = pdf.Pages.Count pdf.LoadFromFile(path) End If If cb_zh.Checked = True Then pdf.LoadFromFile(path) pdf_page = pdf.Pages.Count pdf.PrintFromPage = pdf_page pdf.PrintToPage = pdf_page End If If cb_zd.Checked = True Then pdf.LoadFromFile(path) pdf_page = pdf.Pages.Count pdf.PrintFromPage = zd_ks.Text pdf.PrintToPage = zd_js.Text End If If cb_ds.Checked = True Then pdf.LoadFromFile(path) pdf_page = pdf.Pages.Count + 1 pdf.PrintFromPage = pdf_page - Val(ds_ks.Text) pdf.PrintToPage = pdf_page - Val(ds_js.Text) End If pdf.PrinterName = pt_list.Text pdf.PrintDocument.Print() End If Application.DoEvents() Next End Sub

Private Function Boo_FileExist(ByVal Str_File As String) As Boolean
   Boo_FileExist = System.IO.File.Exists(Str_File)
End Function
Function pd_file() As Boolean
   Dim temp As String = ""
   For Each file_name In txt_coding.Lines
       If file_name <> "" Then
           If Boo_FileExist(txt_path.Text & file_name & ".pdf") = False Then
               temp = file_name + vbCrLf + temp
           End If
       End If
   Next
   If temp <> "" Then
       MsgBox(temp, MsgBoxStyle.Exclamation, "警告:没有以下文件;请下载!")
       Return False
   Else
       Return True
   End If
End FunctionSub get_pt() ''获取打印机列表
   On Error Resume Next
   Dim prtdoc As New PrintDocument()
   Dim strDefaultPrinter As String = prtdoc.PrinterSettings.PrinterName
   Dim strPrinter As [String]
   For Each strPrinter In PrinterSettings.InstalledPrinters
       pt_list.Items.Add(strPrinter)
       If strPrinter = strDefaultPrinter Then
           pt_list.SelectedIndex = pt_list.Items.IndexOf(strPrinter)
       End If
   Next strPrinter
   pt_list.Text = strDefaultPrinter
End Sub
Sub get_filelist()
   Try
       Dim dirs As String() = Directory.GetFiles(txt_path.Text, "*.pdf")
       Dim dir As String
       Dim filel As String
       For Each dir In dirs
           filel = Split(dir, "\")(UBound(Split(dir, "\")))
           txt_coding.Text = Split(filel, ".pdf")(0) + vbCrLf + txt_coding.Text
           Application.DoEvents()
       Next
   Catch e As Exception
       MsgBox("文件列表获取失败!", vbInformation, "VB小源码")
   End Try
End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_pt_pdf.Click
   If txt_coding.Text <> "" Then
       PT_PDF()
   Else
       MsgBox("请输入文件名或者获取文件列表!", MsgBoxStyle.Information, "VB小源码")
   End IfEnd SubPrivate Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_zh.CheckedChanged
   If cb_zh.Checked = True Then
       cb_all.Checked = False
       cb_zd.Checked = False
       zd_ks.Enabled = False
       zd_js.Enabled = False
       cb_ds.Checked = False
       ds_ks.Enabled = False
       ds_js.Enabled = False
   End If
End SubPrivate Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_zd.CheckedChanged
   If cb_zd.Checked = True Then
       zd_ks.Enabled = True
       zd_js.Enabled = True
       cb_all.Checked = False
       cb_zh.Checked = False
       cb_ds.Checked = False
       ds_ks.Enabled = False
       ds_js.Enabled = False
   End If
End SubPrivate Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_all.CheckedChanged
   If cb_all.Checked = True Then
       zd_ks.Enabled = False
       zd_js.Enabled = False
       cb_zh.Checked = False
       cb_zd.Checked = False
       cb_ds.Checked = False
       ds_ks.Enabled = False
       ds_js.Enabled = False
   End If
End SubPrivate Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_lj.Click
   Dim path_p As String
   get_path_pdf.ShowDialog()
   get_path_pdf.RootFolder = Environment.SpecialFolder.Desktop
   path_p = get_path_pdf.SelectedPath & "\"
   If path_p <> "" Then
       txt_path.Text = path_p
   End IfEnd SubPrivate Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_ds.CheckedChanged
   If cb_ds.Checked = True Then
       zd_ks.Enabled = False
       zd_js.Enabled = False
       cb_zh.Checked = False
       cb_zd.Checked = False
       cb_all.Checked = False
       ds_ks.Enabled = True
       ds_js.Enabled = True
   End If
End SubPrivate Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ds_ks.TextChangedEnd Sub
Private Sub clear_list_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear_list.Click
   txt_coding.Clear()
End SubPrivate Sub 获取文件列表_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles get_file.Click
   If MsgBox("建议:选择少于1000个文件的文件夹获取列表!" & vbCrLf & "是否继续?", vbYesNo, "VB小源码") = vbYes Then
       get_filelist()
   Else
       Exit Sub
   End IfEnd SubPrivate Sub ds_js_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ds_js.TextChanged
   ds_ks.Text = ds_js.Text
End SubPrivate Sub zd_ks_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zd_ks.TextChanged
   zd_js.Text = zd_ks.Text
End Sub

End Class

本文分享自微信公众号 - VB小源码(vb_xym),作者:VB小源码

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2019-01-16

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • VB.NET 连接oracle数据库

    大家都知道,开发中连接oracle数据库比较麻烦,要什么客户端之类啊!而且要引用一堆类库,今天我们用Oracle.ManagedDataAccess.Clien...

    巴西_prince
  • VBA批量打印同一文件夹下的Excel文件

    VBA批量打印同一文件夹下的Excel文件!!注意:只能打已经设置好打印范围的Excel文件!!如果想打印任意数据区域请自行增加!!

    巴西_prince
  • VB.NET Excel操作类(获取工作簿列表和工作表列表及工作表对象)

    巴西_prince
  • 为什么要在离线A/B测试中使用贝叶斯方法?

    当涉及到假设检验时,贝叶斯方法可以取代经典的统计方法。这里将使用web分析的具体案例来演示我们的演示。

    磐创AI
  • VB.NET 服务端源码

    Imports System.Net Imports System.Net.Sockets Imports System.Threading Imports S...

    巴西_prince
  • (含源码)「自然语言处理(NLP)」Question Answering(QA)论文整理(二)

    本次整理的论文主要偏向于Open-Domain QA,共8篇文章,其中主要涉及到混合注意力方法、预训练模型分析、BERT预训练模型优化、QA数据集、问答跳转等...

    ShuYini
  • 在Chrome中截取整个网页

    经常使用谷歌浏览器的话,如果要想对网页截图,大多都直接使用系统自带截屏方式或者第三方截屏。但如果要把网页整个截取下来的话,你可以试试Chrome自带的截屏功能。...

    Inkedus
  • 关于面试题 Array.indexof() 方法的实现及思考

    这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了。 昨天看到有网友说面试中也碰到过这个问题,我就重新...

    叙帝利
  • 使用 pdf.js 跨域问题的处理方法1

    在《使用 pdf.js 在网页中加载 pdf 文件》中详细介绍了 pdf.js 的使用与集成网页开发的基本方法。展示效果如下图:

    张传宁老师
  • CCF201312-1

    试题编号: 201312-1 试题名称: 出现次数最多的数 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问...

    用户4492257

扫码关注云+社区

领取腾讯云代金券