c#发送文件(pdf, html或rtf)到打印机
本文关键字:rtf 打印机 html 文件 pdf | 更新日期: 2023-09-27 18:01:44
我在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);
}
但是,我得到一个错误:
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
你可以使用Free . net PDF Library (Free, on visualstudiogallery)。将PDF转换为图像并使用PrintDocument打印....
For Spire。. NET (from教程)
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
Bitmap bmp = doc.SaveAsImage(0);
bmp.Save("convertToBmp.bmp", ImageFormat.Bmp);