7 Replies - 21765 Views - Last Post: 23 May 2011 - 04:54 PM Rate Topic: -----

#1 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 03:44 PM

Here's the basic premise:

My user clicks some gizmos and a PDF file is spit out to his desktop. Is there some way for me to send this file to the printer queue and have it print to the locally connected printer?

string filePath = "filepathisalreadysethere";
SendToPrinter(filePath); //Something like this?


He will do this process many times. For each student in a classroom he has to print a small report card. So I generate a PDF for each student, and I'd like to automate the printing process instead of having the user generated pdf, print, generate pdf, print, generate pdf, print.

Any suggestions on how to approach this? I'm running on Windows XP with Windows Forms .NET 4. I don't need any help generating this file, just need help sending it to the printer. Googling has lead me to many 2006 articles that don't really help me at all. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How can I send a PDF document to the printer and have it print?

#2 MATTtheSEAHAWK   User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:03 PM

Well I did some looking around and found an article on stack overflow. It looks like it talks about having to use a print dialog to choose the print name but maybe you can somehow do it without showing the file dialog.

Here is the article on doing the printing:
http://stackoverflow...ther-files-in-c

Here is something I found on how to get the printer names:
http://msdn.microsof...edprinters.aspx

I hope this is what you needed and good luck with it :)
Was This Post Helpful? 1
  • +
  • -

#3 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:04 PM

This thread might help.

http://social.msdn.m...85-f67b9dd2f2e8

Not the one marked as answer, but one of the ones after it, the ones with some code.
Was This Post Helpful? 1
  • +
  • -

#4 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:10 PM

Hm... found this in your link Curtis:

printjob.StartInfo.FileName = targetFile;
printjob.StartInfo.Verb = "Print";
printjob.UseShellExecute = true;
printjob.StartInfo.CreateNoWindow = true;
printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

PrinterSettings setting = new PrinterSettings();

setting.DefaultPageSettings.Landscape = true;

printjob.Start();


I'm assuming printJob is a Process object?

This post has been edited by Sergio Tapia: 23 May 2011 - 04:13 PM

Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:14 PM

No idea. I typically work with Silverlight...I haven't had to worry about printing too much lately.

The "PrinterSettings" object there is obviously doing nothing, though.
Was This Post Helpful? 0
  • +
  • -

#6 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:17 PM

Yeah I noticed that. I wonder what I have to assign those settings to.
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:21 PM

Anyway, I was thinking more along the lines of the post above it. Starting an Acrobat (or Reader) process with command line switches that causes it to print.
Was This Post Helpful? 0
  • +
  • -

#8 MATTtheSEAHAWK   User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: How can I send a PDF document to the printer and have it print?

Posted 23 May 2011 - 04:54 PM

View PostSergio Tapia, on 23 May 2011 - 07:10 PM, said:

Hm... found this in your link Curtis:

printjob.StartInfo.FileName = targetFile;
printjob.StartInfo.Verb = "Print";
printjob.UseShellExecute = true;
printjob.StartInfo.CreateNoWindow = true;
printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

PrinterSettings setting = new PrinterSettings();

setting.DefaultPageSettings.Landscape = true;

printjob.Start();


I'm assuming printJob is a Process object?


Actually no it's a ProcessStartInfo. I agreed with you and then I double checked and noticed it was this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1