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

发布于:2024-04-19 ⋅ 阅读:(24) ⋅ 点赞:(0)

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