简体   繁体   English

使用Adobe Reader进行PDF直接打印

[英]PDF direct printing using adobe reader

I tried this code for PDF printing but when Adobe Reader open this gives an error that 我尝试使用此代码进行PDF打印,但是当Adobe Reader打开时,出现了以下错误

file and directory could not found 找不到文件和目录

The code runs fine and opens Adobe but does not load the file for printing. 该代码可以正常运行并打开Adobe,但不会加载文件进行打印。 Instead it shows an error dialog. 而是显示一个错误对话框。 Can anybody tell me where I am wrong? 谁能告诉我我哪里错了?

private void PrintFormPdfData(byte[] formPdfData)
    {`enter code here`
        string tempFile;

        tempFile = Path.GetTempFileName();



        using (FileStream fs = new FileStream(tempFile, FileMode.Create))
        {
            fs.Write(formPdfData, 0, formPdfData.Length);
            fs.Flush();
        }

        try
        {
            string gsArguments;
            string gsLocation;
            ProcessStartInfo gsProcessInfo;
            Process gsProcess;

            gsArguments = string.Format("-grey -noquery -printer \"HP LaserJet 5M\" \"{0}\"", tempFile);
            gsLocation = @"C:\Program Files\Ghostgum\gsview\gsprint.exe";

            gsProcessInfo = new ProcessStartInfo();
            gsProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;
            gsProcessInfo.FileName = gsLocation;
            gsProcessInfo.Arguments = gsArguments;

            gsProcess = Process.Start(gsProcessInfo);
            gsProcess.WaitForExit();
        }
        finally
        {
            File.Delete(tempFile);
        }
    }

fs.Close() is missing. fs.Close()丢失。 So the file cannot be opened by gsprint. 因此,该文件无法通过gsprint打开。

Note: Flush before Close is useless. 注意:在关闭之前进行冲洗是没有用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM