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

PDF提取

一、PDF提取功能,看图

d68fad88efc059aeaa351187eb0a44b7.png

二、PDF提取界面

ff90001cd028c85a559d042d25926226.png

三、PDF提取代码

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

private void button9_Click(object sender, EventArgs e)

{
     string oneFilePath = GetOneFilepath();
     if (!string.IsNullOrEmpty(oneFilePath))
       {
          textBox3.Text = oneFilePath;
       }
 }

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

private void button10_Click(object sender, EventArgs e)
  {
      string FileFolder = SelectFolder();
      if (!string.IsNullOrEmpty(FileFolder))
      {
         textBox4.Text = FileFolder;
      }
 }

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

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部分页面

6084d73b602ec547df240782ffb46d3b.png

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

71b9c538dc4f254910c9f71b9a607c68.png

发信息“PDF”,获取“PDF工具”

关注,阅读更多文章

ab31925ba936e1fad47f30aa73f9d61d.jpeg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值