Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/341.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、html或rtf)发送到打印机_C# - Fatal编程技术网

C# 将文件(pdf、html或rtf)发送到打印机

C# 将文件(pdf、html或rtf)发送到打印机,c#,C#,我在用C#打印文件时遇到问题。如何打印具有双面打印可能性的任何文件 ProcessStartInfo info = new ProcessStartInfo(); info.Verb = "print"; info.FileName = @"c:\output.pdf"; info.CreateNoWindow = true; info.WindowStyle = ProcessWindowStyle.Hidden;

我在用C#打印文件时遇到问题。如何打印具有双面打印可能性的任何文件

        ProcessStartInfo info = new ProcessStartInfo();
        info.Verb = "print";
        info.FileName = @"c:\output.pdf";
        info.CreateNoWindow = true;
        info.WindowStyle = ProcessWindowStyle.Hidden;

        Process p = new Process();
        p.StartInfo = info;
        p.Start();

        p.WaitForInputIdle();
        System.Threading.Thread.Sleep(3000);
        if (false == p.CloseMainWindow())
            p.Kill();
但是我不满意,因为我不能在这里设置打印参数。如何使用
PrintDocument
类完成此操作

我使用Spire PDF将PDF转换为图像

            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("e:\\proba1.pdf");

            BitmapSource source;
            Bitmap bmp;

            for (int i = 1; i < pdf.Pages.Count + 1; i++)
            {
                source = pdf.SaveAsImage(i);
                bmp = SourceToBitmap(source);
                bmp.Save(string.Format("result-{0}.png", i), ImageFormat.Png);
            }

您可以使用免费的.NET PDF库(在visualstudiogallery上免费)。将PDF转换为图像,并使用PrintDocument打印此文件….

For Spire.NET(来自教程)


有什么问题吗?我想按原样打印文件,而不设置字体等。
StreamReader
不要按以下方式打印我要的pdf文件:c#打印pdf文件c#打印pdf文件库->在第三个位置(在我的搜索结果中),有必要转换图像?如果你想按代码打印,是的,如果你使用Fox IT库,你可以直接打印它(但你需要付费…),好的,利用免费版本免费的.NET PDF库。因此,我需要转换图像,并使用c#So?中可用的函数打印图像。对于上述库的转换使用,您应该仔细查看该库:有一种方法可以“打开”pdf、“枚举”页面、“提取”页面为图像->然后打印标准函数(虽然您需要编写一些代码,但它不仅是“打印图像”,而且您可以在MSDN中找到)。
Error   1   Cannot implicitly convert type 'System.Drawing.Image' to 'System.Windows.Media.Imaging.BitmapSource'    C:\Users\Łukasz\documents\visual studio 2013\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs    90  26  FileMonitor
Error   2   The name 'SourceToBitmap' does not exist in the current context C:\Users\Łukasz\documents\visual studio 2013\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs    91  23  FileMonitor
Error   3   The name 'ImageFormat' does not exist in the current context    C:\Users\Łukasz\documents\visual studio 2013\Projects\WpfApplication1\WpfApplication1\MainWindow.xaml.cs    92  62  FileMonitor
PdfDocument doc = new PdfDocument(); 
doc.LoadFromFile("sample.pdf"); 
Bitmap bmp = doc.SaveAsImage(0); 
bmp.Save("convertToBmp.bmp", ImageFormat.Bmp);