Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么不';t 2 pdf文件正在合并?_C#_Asp.net_Asp.net Mvc 4_C# 4.0_Itext - Fatal编程技术网

C# 为什么不';t 2 pdf文件正在合并?

C# 为什么不';t 2 pdf文件正在合并?,c#,asp.net,asp.net-mvc-4,c#-4.0,itext,C#,Asp.net,Asp.net Mvc 4,C# 4.0,Itext,我正在将2个PDF文件合并为一个,但它不会合并任何内容,即使没有显式错误。我已经试了很多次了,但还是做不好。这是我正在使用的项目中的文件夹。允许写入权限,并允许在其中写入和创建文件 publicstaticvoidmergefiles(stringdestinationfile,string[]sourceFiles){ 试一试{ sourceFiles=新字符串[2]{ HostingEnvironment.MapPath(@//下载/证书/检查报告(78.pdf)), HostingEnvi

我正在将2个PDF文件合并为一个,但它不会合并任何内容,即使没有显式错误。我已经试了很多次了,但还是做不好。这是我正在使用的项目中的文件夹。允许写入权限,并允许在其中写入和创建文件

publicstaticvoidmergefiles(stringdestinationfile,string[]sourceFiles){
试一试{
sourceFiles=新字符串[2]{
HostingEnvironment.MapPath(@//下载/证书/检查报告(78.pdf)),
HostingEnvironment.MapPath(@/下载/证书/检查报告(78.pdf))
};
//outputPdfPath=Path.GetFileName(“~/Downloads/Certificates/119.FDV-3686.pdf”);
destinationFile=HostingEnvironment.MapPath(@//下载/证书/检查报告(78.pdf));
int f=0;
//我们为某个文档创建一个阅读器
PdfReader reader=新的PdfReader(sourceFiles[f]);
//我们检索总页数
int n=reader.NumberOfPages;
//WriteLine(“原始文件中有“+n+”个页面”);
//步骤1:创建文档对象
Document Document=新文档(reader.GetPageSizeWithRotation(1));
//步骤2:我们创建一个侦听文档的编写器
PdfWriter writer=PdfWriter.GetInstance(文档,新文件流(destinationFile,FileMode.Create));
//步骤3:我们打开文档
document.Open();
PdfContentByte cb=writer.DirectContent;
PDF导入页面;
整数旋转;
//步骤4:我们添加内容
while(f
我使用using语句合并多个pdf文件以完成此操作。希望这有帮助

using (var fs = new FileStream(HttpContext.Current.Server.MapPath(outputFilepath),FileMode.Create))
{
    using (var document = new Document())
    {
        using (var pdfCopy = new PdfCopy(document, fs))
        {
            document.Open();

            for (var i = 0; i < numberOfFilesToMerge; i++)
            {
                using (var pdfReader = new PdfReader(sourceFiles[i]))
                {
                    for (var page = 0; page < pdfReader.NumberOfPages;)
                    {
                        pdfCopy.AddPage(pdfCopy.GetImportedPage(pdfReader, ++page));
                    }
                }
            }
        }
     }
 }
使用(var fs=new FileStream(HttpContext.Current.Server.MapPath(outputFilepath),FileMode.Create))
{
使用(var document=new document())
{
使用(var pdfCopy=新pdfCopy(文档,fs))
{
document.Open();
对于(var i=0;i
您试图同时写入要读取的文件。使用不同的结果文件名。