请教关于pdf插入的问题
请教关于pdf插入的问题
目标:
文件夹1中有1101、1102、1103等文件夹,文件夹里面有对应名称的1101、1102、1103等pdf文件,有5页到10页不等。
文件夹2中有1101、1102、1103等pdf文件,只有一页,这一页正在1目录下对应文件名的pdf第三页所缺少页。
文件夹1内容: 文件夹2内容:


思路:借助第三方软件Spire.PDF
1、 遍历获取文件夹1中所有pdf文件(完整路径并放在listbox1中),遍历文件夹2中所有pdf文件,放在listbox2中。
2、 判断如果说listbox2中路径及文件名完全等于listbox1的路径及文件名,采用pdf的复制插入操作,循环次数以2文件夹中pdf个数为依据,2中没有的pdf就不用管。
不知道这么想是否正确?请老师指教为谢!
代码实现了思路1功能,但到第二步代码写不出来,还请各位老师教教学生,谢谢!
附窗体及代码,也在网上找到一部分教程,无法参透。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.IO;
namespace wenjianjia
{
public partial class MergePDF : Form
{
public MergePDF()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog FBDialog = new FolderBrowserDialog();
if (FBDialog.ShowDialog() == DialogResult.OK)
{
string strPath = FBDialog.SelectedPath;
if (strPath.EndsWith("\\"))
textBox1.Text = strPath;
else
textBox1.Text = strPath + "\\";
}
DirectoryInfo theFolder = new DirectoryInfo(textBox1.Text);
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
foreach (DirectoryInfo NextFolder in dirInfo)
{
FileInfo[] fileInfo = NextFolder.GetFiles("*.pdf");
foreach (FileInfo NextFile in fileInfo)
{
this.listBox1.Items.Add(theFolder+NextFile.Name);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog FYDialog = new FolderBrowserDialog();
if (FYDialog.ShowDialog() == DialogResult.OK)
{
string stPath = FYDialog.SelectedPath;
if (stPath.EndsWith("\\"))
textBox2.Text = stPath;
else
textBox2.Text = stPath + "\\";
}
DirectoryInfo eFolder = new DirectoryInfo(textBox2.Text);
DirectoryInfo[] rInfo = eFolder.GetDirectories();
foreach (DirectoryInfo NextFolder in rInfo)
{
FileInfo[] eInfo = NextFolder.GetFiles("*.pdf");
foreach (FileInfo tFile in eInfo)
{
this.listBox2.Items.Add(eFolder+tFile.Name);
}
}
}
}
}
网上百度到的pdf代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace 复制PDF页面到另一个PDF文档
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc1 = newPdfDocument();
doc1.LoadFromFile("童话故事.pdf");
PdfDocument doc2 = newPdfDocument();
doc2.LoadFromFile("各种点心的做法.pdf");
PdfPageBase page = doc1.Pages[0];
SizeF size = page.Size;
PdfTemplate template = page.CreateTemplate();
doc2.Pages.Insert(1, size, new PdfMargins(0, 0));
doc2.Pages[1].Canvas.DrawTemplate(template, newPointF(0, 0));
doc2.SaveToFile("复制.pdf");
System.Diagnostics.Process.Start("复制.pdf");
}
}
}
目标:
文件夹1中有1101、1102、1103等文件夹,文件夹里面有对应名称的1101、1102、1103等pdf文件,有5页到10页不等。
文件夹2中有1101、1102、1103等pdf文件,只有一页,这一页正在1目录下对应文件名的pdf第三页所缺少页。
文件夹1内容: 文件夹2内容:


思路:借助第三方软件Spire.PDF
1、 遍历获取文件夹1中所有pdf文件(完整路径并放在listbox1中),遍历文件夹2中所有pdf文件,放在listbox2中。
2、 判断如果说listbox2中路径及文件名完全等于listbox1的路径及文件名,采用pdf的复制插入操作,循环次数以2文件夹中pdf个数为依据,2中没有的pdf就不用管。
不知道这么想是否正确?请老师指教为谢!
代码实现了思路1功能,但到第二步代码写不出来,还请各位老师教教学生,谢谢!
附窗体及代码,也在网上找到一部分教程,无法参透。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.IO;
namespace wenjianjia
{
public partial class MergePDF : Form
{
public MergePDF()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog FBDialog = new FolderBrowserDialog();
if (FBDialog.ShowDialog() == DialogResult.OK)
{
string strPath = FBDialog.SelectedPath;
if (strPath.EndsWith("\\"))
textBox1.Text = strPath;
else
textBox1.Text = strPath + "\\";
}
DirectoryInfo theFolder = new DirectoryInfo(textBox1.Text);
DirectoryInfo[] dirInfo = theFolder.GetDirectories();
foreach (DirectoryInfo NextFolder in dirInfo)
{
FileInfo[] fileInfo = NextFolder.GetFiles("*.pdf");
foreach (FileInfo NextFile in fileInfo)
{
this.listBox1.Items.Add(theFolder+NextFile.Name);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog FYDialog = new FolderBrowserDialog();
if (FYDialog.ShowDialog() == DialogResult.OK)
{
string stPath = FYDialog.SelectedPath;
if (stPath.EndsWith("\\"))
textBox2.Text = stPath;
else
textBox2.Text = stPath + "\\";
}
DirectoryInfo eFolder = new DirectoryInfo(textBox2.Text);
DirectoryInfo[] rInfo = eFolder.GetDirectories();
foreach (DirectoryInfo NextFolder in rInfo)
{
FileInfo[] eInfo = NextFolder.GetFiles("*.pdf");
foreach (FileInfo tFile in eInfo)
{
this.listBox2.Items.Add(eFolder+tFile.Name);
}
}
}
}
}
网上百度到的pdf代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace 复制PDF页面到另一个PDF文档
{
class Program
{
static void Main(string[] args)
{
PdfDocument doc1 = newPdfDocument();
doc1.LoadFromFile("童话故事.pdf");
PdfDocument doc2 = newPdfDocument();
doc2.LoadFromFile("各种点心的做法.pdf");
PdfPageBase page = doc1.Pages[0];
SizeF size = page.Size;
PdfTemplate template = page.CreateTemplate();
doc2.Pages.Insert(1, size, new PdfMargins(0, 0));
doc2.Pages[1].Canvas.DrawTemplate(template, newPointF(0, 0));
doc2.SaveToFile("复制.pdf");
System.Diagnostics.Process.Start("复制.pdf");
}
}
}
...全文
相关推荐
论文研究-求解带时间窗车辆路径问题的插入检测法.pdf
论文研究-求解带时间窗车辆路径问题的插入检测法.pdf, 在求解带时间窗
WPS公式插入一些问题.pdf
WPS 公式插入技巧WPS 是一个功能强大且常用的办公软件,但是在插入数学公式时,用户常常会遇到一些问题。本文将为读者介绍 WPS 中快速录入一般数学公式的技巧。
论文研究-求解TSP问题的最近邻域与插入混合算法.pdf
论文研究-求解TSP问题的最近邻域与插入混合算法.pdf, 研究了求解旅
解决latex无法插入svg格式图片问题,采用inkscape软件一键将当前文件夹下所有svg图片转换为pdf格式
解决latex无法插入svg格式图片问题,采用inkscape软件一键将当前文件夹下所有svg图片转换为pdf格式1、下载并安装lnkspace软件。国内的也可以。2、新建环境变量,变量名:path。
在Latex中插入多页pdf文档的命令
={2}]{fig5.pdf}}]{fig5.pdf} ```#### 七、常见问题及解决方法1.


