0

I am trying to learn, if it's possible to create an application in C# which needs to meet requirements:

  1. Can load a template PDF file, and draw some text on top of it (positioned by pixels for example)
  2. Save this file in a specific directory
  3. And most important... Application should be able to print such PDF file. And i don't mean print it on the screen, i mean 'silently' send on the printer.

I've heard, that two first points can be accomplished by iTextSharp/iTextPdf. But does it allow me to simply send this file to the printer? I was looking for a solution for a while now.
User should pick default printer once in options, and all he should do is click "print" after generating such PDF file. I would love the solution that doesn't open Adobe Reader in the background.

Are there maybe some alternatives?

I know its possible to send images to printer like that, without running any other program in the background. But I need it to work for PDFs.

 private void SendToPrinter(string path)
 {
     PrinterSettings defaultprinter = new PrinterSettings();
     PrintDocument pd = new PrintDocument(); 
     pd.PrinterSettings.PrinterName = defaultprinter.PrinterName;
     pd.PrintPage += (sender, e) => PrintPage(e, path);
     pd.Print();
 }
 private void PrintPage(PrintPageEventArgs e, string path)
 {
     Bitmap bitma = new Bitmap(776, 538, PixelFormat.Format32bppArgb);
     System.Drawing.Image dest = bitma;
     Graphics graph = Graphics.FromImage(dest);
     graph.Clear(Color.FromArgb(255, 255, 255));

     Bitmap z = new Bitmap(path);
     System.Drawing.Image img = z;
     graph.DrawImage(img, new System.Drawing.Point(120, 350));
     e.Graphics.DrawImage(dest, new System.Drawing.Point(0, 0));
 }

PS. Yes, I've tried searching. Google, stackoverflow, seen even few similar questions, but didn't find one answering all my questions.

Kedor
  • 1,488
  • 5
  • 29
  • 53

1 Answers1

0

If you look at the different Questions I put myself here in SO You'll see that using GhostScript in order to print pdf files it's a great tool. You can find the Questions here, here, here and here.

Between the 4 of them you'll find all the information you need :)

Community
  • 1
  • 1
Miquel Coll
  • 759
  • 15
  • 49