C# 将两个PDF文档合并为一个
我可以在asp.net中合并两个或多个PDF吗?我知道我可以使用interop处理Word和Excel文件。但是我可以合并PDF吗 请提供任何建议或链接。尝试: iTextSharp是iText的一个C#端口,是用于 PDF生成和操作。它可以用来创建PDF 从头开始创建文档,将XML转换为PDF(使用额外的XFA Worker DLL),用于填写交互式PDF表单,为新内容加盖戳记 在现有PDF文档上,要拆分和合并现有PDF文档, 还有更多 关于如何做到这一点。尝试:C# 将两个PDF文档合并为一个,c#,asp.net,pdf,C#,Asp.net,Pdf,我可以在asp.net中合并两个或多个PDF吗?我知道我可以使用interop处理Word和Excel文件。但是我可以合并PDF吗 请提供任何建议或链接。尝试: iTextSharp是iText的一个C#端口,是用于 PDF生成和操作。它可以用来创建PDF 从头开始创建文档,将XML转换为PDF(使用额外的XFA Worker DLL),用于填写交互式PDF表单,为新内容加盖戳记 在现有PDF文档上,要拆分和合并现有PDF文档, 还有更多 关于如何做到这一点。尝试: using System.T
using System.Text.RegularExpressions;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iTextSharp.text;
//Call this method in main with parameter
public static void MergePages(string outputPdfPath, string[] lstFiles)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage;
sourceDocument = new Document();
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
try
{
for (int f = 0; f < lstFiles.Length - 1; f++)
{
int pages = 1;
reader = new PdfReader(lstFiles[f]);
//Add pages of current file
for (int i = 1; i <= pages; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
reader.Close();
}
sourceDocument.Close();
}
catch (Exception ex)
{
throw ex;
}
}
iTextSharp是iText的一个C#端口,是用于
PDF生成和操作。它可以用来创建PDF
从头开始创建文档,将XML转换为PDF(使用额外的XFA
Worker DLL),用于填写交互式PDF表单,为新内容加盖戳记
在现有PDF文档上,要拆分和合并现有PDF文档,
还有更多
使用System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using iTextSharp.text;
//Call this method in main with parameter
public static void MergePages(string outputPdfPath, string[] lstFiles)
{
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage;
sourceDocument = new Document();
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
try
{
for (int f = 0; f < lstFiles.Length - 1; f++)
{
int pages = 1;
reader = new PdfReader(lstFiles[f]);
//Add pages of current file
for (int i = 1; i <= pages; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
reader.Close();
}
sourceDocument.Close();
}
catch (Exception ex)
{
throw ex;
}
}
使用iTextSharp.text.pdf;
使用iTextSharp.text.pdf.parser;
使用iTextSharp.text;
//使用参数在main中调用此方法
公共静态void合并页面(字符串outputPdfPath,字符串[]lstFiles)
{
PdfReader reader=null;
Document sourceDocument=null;
PdfCopy pdfCopyProvider=null;
PDF导入页面导入页面;
sourceDocument=新文档();
pdfCopyProvider=新的PdfCopy(sourceDocument,
新的System.IO.FileStream(outputPdfPath,System.IO.FileMode.Create));
Open();
尝试
{
对于(int f=0;f使用System.Text.RegularExpressions;
使用iTextSharp.text.pdf;
使用iTextSharp.text.pdf.parser;
使用iTextSharp.text;
//使用参数在main中调用此方法
公共静态void合并页面(字符串outputPdfPath,字符串[]lstFiles)
{
PdfReader reader=null;
Document sourceDocument=null;
PdfCopy pdfCopyProvider=null;
PDF导入页面导入页面;
sourceDocument=新文档();
pdfCopyProvider=新的PdfCopy(sourceDocument,
新的System.IO.FileStream(outputPdfPath,System.IO.FileMode.Create));
Open();
尝试
{
对于(int f=0;f 对于(int i=1;我看一下这里它可能会帮助您看一下这里它可能会帮助您我只能使用您建议的代码合并PDF,或者任何其他格式也可以合并。?或从doc到PDF或.xls到PDF。?这些操作可以完成吗。?抱歉,iTextSharp只能从html、xml或编程方式创建PDF。您可以打开doc使用LibreOffice使用此处描述的方法转换为PDF:@Ankur请注意,此合并例程不是iText(Sharp)的最佳合并代码.PdfWriter
用于创建新文档。如果要从已存在的源文档集合中复制页面,应使用PdfCopy。
Cf.本书中的示例。@Ryan Weir:对于某些PDF,我遇到了以下错误“PdfReader未使用所有者密码打开”。请帮助。@Ankur:我刚检查过,您是对的,在更新版本的iTextSharp中,您在中提到的不道德阅读
属性不再可用。请尝试将项目中使用的iTextSharp版本降级为4.0.3,如所示-希望您不会使用比此版本更新的任何功能。最坏的情况是加密PDF您检测到它们上的异常并使用旧库。我只能使用您建议的代码合并PDF,或者也可以合并任何其他格式。?或从doc到PDF或.xls到PDF。?这些操作可以完成吗。?抱歉,iTextSharp只能从html、xml或编程方式创建PDF。您可以使用Libr将文档转换为PDFeOffice使用此处描述的方法:@Ankur请注意,此合并例程不是iText(Sharp)的最佳合并代码.PdfWriter
用于创建新文档。如果要从已存在的源文档集合中复制页面,应使用PdfCopy。
Cf.本书中的示例。@Ryan Weir:对于某些PDF,我遇到了以下错误“PdfReader未使用所有者密码打开”。请帮助。@Ankur:我刚检查过,您是对的,在更新版本的iTextSharp中,您在中提到的不道德阅读
属性不再可用。请尝试将项目中使用的iTextSharp版本降级为4.0.3,如所示-希望您不会使用比此版本更新的任何功能。最坏的情况是加密PDF您可以检测到它们上的异常并使用旧库。