I have a problem with printing the files in C #. How to print any file with the possibility of two-sided printing.
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();
But it does not satisfy me, because I can not here set the print parameters. How can I do this using the PrintDocument
class?
I using Spire PDF to convert pdf to image.
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);
}
But, I get a error:
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
You can use Free .NET PDF Library (free, on visualstudiogallery). Convert the PDF to Image and print this with PrintDocument ....
For Spire.NET (from tutorial)
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
Bitmap bmp = doc.SaveAsImage(0);
bmp.Save("convertToBmp.bmp", ImageFormat.Bmp);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.