前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在C#中,PDFsharp库使用(三):PDF提取

在C#中,PDFsharp库使用(三):PDF提取

作者头像
哆哆Excel
发布2024-04-18 19:46:17
2050
发布2024-04-18 19:46:17
举报
文章被收录于专栏:哆哆Excel哆哆Excel

一、PDF提取功能,看图

二、PDF提取界面

三、PDF提取代码

//pdf提取---选择文件Button

private void button9_Click(object sender, EventArgs e)

代码语言:javascript
复制
 {
     string oneFilePath = GetOneFilepath();
     if (!string.IsNullOrEmpty(oneFilePath))
       {
          textBox3.Text = oneFilePath;
       }
 }

//pdf提取---输出目录Button

代码语言:javascript
复制
 private void button10_Click(object sender, EventArgs e)
  {
      string FileFolder = SelectFolder();
      if (!string.IsNullOrEmpty(FileFolder))
      {
         textBox4.Text = FileFolder;
      }
 }

//pdf提取---执行提取Button

代码语言:javascript
复制
  private void button11_Click(object sender, EventArgs e)
  {
       int x = (int)numericUpDown2.Value;
       int y= (int)numericUpDown3.Value;
       string inputFilePath = textBox3.Text;
       string outputDirectory = textBox4.Text;
        // 确保输出目录存在
        if (!Directory.Exists(outputDirectory))
            {
                Directory.CreateDirectory(outputDirectory);
            }
       string outputFilePath1 = Path.Combine(outputDirectory, $"{Path.GetFileNameWithoutExtension(inputFilePath)}_{x}-{y}.pdf");
       string outputFilePath2 = Path.Combine(outputDirectory, $"{Path.GetFileNameWithoutExtension(inputFilePath)}_other.pdf");
       ExtractPages(inputFilePath, x, y, outputFilePath1);
       SaveRemainingPages(inputFilePath, x, y, outputFilePath2);
       MessageBox.Show("完成", "提示");
}

//ExtractPages函数,作用是提取指定PDF部分页面

//SaveRemainingPages函数,作用是上面提取完成后留下的部分,保存为另一个文件

本文参与?腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2024-04-17,如有侵权请联系?cloudcommunity@tencent.com 删除

本文分享自 哆哆Excel 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com