下面代码的目的是将另外一个PDF文件(file2)内容追加到第一个PDF文件(file)尾,但合并的结果是第一个文件的内容被覆盖了。
System.IO.FileStream fs = new System.IO.FileStream(file.FullName,System.IO.FileMode.Append,System.IO.FileAccess.Write); System.IO.FileStream sr = new System.IO.FileStream(file2.FullName,System.IO.FileMode.Open);
byte[] bData = new byte[sr.Length];
sr.Read(bData,0,bData.Length);
fs.Write(bData,0,bData.Length);sr.Close();
fs.Flush();
fs.Close();请问怎么解决被覆盖的问题。
还有如果合并成功,如何保证追加的内容是另起一页。
谢谢!
System.IO.FileStream fs = new System.IO.FileStream(file.FullName,System.IO.FileMode.Append,System.IO.FileAccess.Write); System.IO.FileStream sr = new System.IO.FileStream(file2.FullName,System.IO.FileMode.Open);
byte[] bData = new byte[sr.Length];
sr.Read(bData,0,bData.Length);
fs.Write(bData,0,bData.Length);sr.Close();
fs.Flush();
fs.Close();请问怎么解决被覆盖的问题。
还有如果合并成功,如何保证追加的内容是另起一页。
谢谢!
解决方案 »
- 高分求有效答案!
- 求解决socket连接异常导致断线
- 一个有意思的证明(有意义的回帖均可得分,分不够的话开帖另给!)
- axWebBrowser1.Navigate 参数问题
- 熟悉DTS的朋友请进
- 在循环获取数据库中的数据,如何让dataGridView1有一条数据就显示一条
- C# .NET + SQL SERVER 工程师深圳工作调查
- C#和Matlab混合编程生成的DLL在控制台程序中运行正常,但放到REST WCF中就报错:MWArray TypeInitializationExcepti
- C#windows编程和用win32(API直接或MFC或VB60方式)windows编程哪个更好?
- 能不能在一个类里面,复制以前保存过的一个实例到本类中来?
- 谁有使用异步通讯实现同步效果(伪同步)的经验
- C#
internal void PopulateRelatedObjects(PdfFile PdfFile,
Hashtable container)
{
Match m = Regex.Match(this.OriginalText, @"\d+ 0 R[^G]");
while (m.Success)
{
int num=int.Parse(
m.Value.Substring(0,m.Value.IndexOf(" ")));
bool notparent = !Regex.IsMatch(this.OriginalText,
@"/Parent\s+"+num+" 0 R");
if (notparent &! container.Contains(num))
{
PdfFileObject pfo = PdfFile.LoadObject(num);
if (pfo != null & !container.Contains(pfo.number))
{
container.Add(num,null);
pfo.PopulateRelatedObjects(PdfFile, container);
}
}
m = m.NextMatch();
}
}
这地方写的很详细
http://www.codeproject.com/KB/cs/giospdfsplittermerger.aspx?fid=247540&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=1
并不是你的程序有问题,而在于格式。
pdf格式是从后向前看的。一般来讲,每段开头是定义本段的名称和数据等信息。
而结尾才是定义本文章的内容排列顺序等总的信息。
所以,你的程序处理后的那个文件,再次打开后,pdf阅读器从后向前查找定义,根本找不到第一个文件的那些说明,所以,就不显示。