Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.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#打印一份pdf文件并重叠处理_C#_Visual Studio_Printing_Merge - Fatal编程技术网

C#打印一份pdf文件并重叠处理

C#打印一份pdf文件并重叠处理,c#,visual-studio,printing,merge,C#,Visual Studio,Printing,Merge,当我打印文件A.pdf和B.pdf时,我运行以下代码: if (File.Exists(@"C:\Users\Luca\Desktop\A.pdf") == true && File.Exists(@"C:\Users\Luca\Desktop\B.pdf") == true) { using (PdfDocument one = PdfReader.Open(@"C:\Users\Luca\Desktop\A.pdf", PdfDocum

当我打印文件A.pdf和B.pdf时,我运行以下代码:

if (File.Exists(@"C:\Users\Luca\Desktop\A.pdf") == true && File.Exists(@"C:\Users\Luca\Desktop\B.pdf") == true)
        {
            using (PdfDocument one = PdfReader.Open(@"C:\Users\Luca\Desktop\A.pdf", PdfDocumentOpenMode.Import))
            using (PdfDocument two = PdfReader.Open(@"C:\Users\Luca\Desktop\B.pdf", PdfDocumentOpenMode.Import))
            using (PdfDocument outPdf = new PdfDocument())

            {
                CopyPages(one, outPdf);
                CopyPages(two, outPdf);

                outPdf.Save(@"C:\Users\Luca\Desktop\C.pdf");
            }
        }
但是程序显示了一个错误:

"System.IO.IOException: 'The process cannot access the 'C: \ Users \ Luca \ Desktop \ B.pdf' file because it is in use by another process.'.

我尝试使用
Task.Delay(500)的方法
以允许打印时间,但该错误再次显示

以前打开文件失败且文件流仍然打开而未关闭时所导致的错误。 当我遇到类似错误时,重新启动电脑关闭所有应用程序解决了此错误

附加说明
下面的代码永远不会停止您的程序

Task.Delay(500);
我们必须等待任务完成

Task.Delay(500).Wait();

根据我的测试,我没有遇到你得到的错误。不过,我有两个建议。首先,请检查您的pdf文件是否已被其他应用程序使用。其次,您可以将pdf路径放置到d驱动器。