473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

print pdf from C#

I have seen several posts regarding this topic and I have tried some solutions using the System.Diagnostics.Process in .NET 2.0 where impersonation can be easily done by setting the username and password.

Anyway, with or without impersonation the max I could do is to see notepad or acrobat run as a process in the task manager.

My purpose, to print a pdf document, is never achieved. The process starts running and never terminates. Can't understand what is wrong...

This is the code I am testing at the moment:

Process command = new Process();

command.StartInfo.FileName = "C:\\acrobat5\\Reader\\acrord32.exe";
command.StartInfo.Arguments ="/h /p c:\\teste1.pdf";
//impersonating
command.StartInfo.UserName = "Administrator";
command.StartInfo.Domain = "domainX";

System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in "passwordX")
pwd.AppendChar(c);

command.StartInfo.Password = pwd;
command.StartInfo.UseShellExecute = false;
command.StartInfo.CreateNoWindow = true;
command.Start();
command.WaitForExit();
command.Close();

Can someone please help?

Regards,
Andreia
Aug 10 '06 #1
6 28202
Hi.

I'm now struggling with the same task. Did you manage to find a solution? If so, could you be so kind as to share it with me?

Thanks.
May 11 '07 #2
The newer versions of adobe does not take the command /p .. don't know what they use nowadays, but that wont work. you just opened an acrobat file with that command.
May 25 '07 #3
The newer versions of adobe does not take the command /p .. don't know what they use nowadays, but that wont work. you just opened an acrobat file with that command.
I've done it using Acrobat Reader 7. I don't think that the /p parameter is required.

Refer to this article:

http://aspalliance.com/514
May 25 '07 #4
SammyB
807 Expert 512MB
I have seen several posts regarding this topic and I have tried some solutions using the System.Diagnostics.Process in .NET 2.0 where impersonation can be easily done by setting the username and password.

Anyway, with or without impersonation the max I could do is to see notepad or acrobat run as a process in the task manager.

My purpose, to print a pdf document, is never achieved. The process starts running and never terminates. Can't understand what is wrong...

This is the code I am testing at the moment:

Process command = new Process();

command.StartInfo.FileName = "C:\\acrobat5\\Reader\\acrord32.exe";
command.StartInfo.Arguments ="/h /p c:\\teste1.pdf";
//impersonating
command.StartInfo.UserName = "Administrator";
command.StartInfo.Domain = "domainX";

System.Security.SecureString pwd = new System.Security.SecureString();
foreach (char c in "passwordX")
pwd.AppendChar(c);

command.StartInfo.Password = pwd;
command.StartInfo.UseShellExecute = false;
command.StartInfo.CreateNoWindow = true;
command.Start();
command.WaitForExit();
command.Close();

Can someone please help?

Regards,
Andreia
See my solution at http://www.thescripts.com/forum/thread651374.html
It looks a lot like yours but uses StartInfo instead of the command line. HTH --Sam
May 25 '07 #5
I have found a solution on the following website.
printing pdfs in c# - pdfs in c# ausdrucken
The text ist in German but the code sample could be easily understood. The example uses the print verb and closes the acrobat reader instance after the printing.
Sep 10 '07 #6
Well done DotNetDeveloper2007, yours was the final solution after hours of fruitless searching. And the best thing is; you don't need the full path of the app associated with pdf files.

string fileName = "C:\\Test.pdf";
Process proc = new Process ();
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.Verb = "print";
proc.StartInfo.FileName = fileName;
proc.Start();
proc.WaitForExit(10000);
proc.CloseMainWindow();
proc.Close();
Oct 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Michael Foord | last post by:
Here's a little oddity with 'print' being a reserved word... >>> class thing: pass >>> something = thing() >>> something.print = 3 SyntaxError: invalid syntax >>> print something.__dict__...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
0
by: bearophileHUGS | last post by:
There is/was a long discussion about the replacement for print in Python 3.0 (I don't know if this discussion is finished): http://mail.python.org/pipermail/python-dev/2005-September/055968.html ...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
3
by: James J. Besemer | last post by:
I would like to champion a proposed enhancement to Python. I describe the basic idea below, in order to gage community interest. Right now, it's only an idea, and I'm sure there's room for...
69
by: Edward K Ream | last post by:
The pros and cons of making 'print' a function in Python 3.x are well discussed at: http://mail.python.org/pipermail/python-dev/2005-September/056154.html Alas, it appears that the effect of...
2
by: Brad Pears | last post by:
I have some sample code that uses the print dialog, print preview and a print direct options. If I select print preview and then click the printer icon from that, the document prints. If I...
7
by: samslists | last post by:
Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. Is this at least being considered as an option for 2.6? It seems...
12
by: Studiotyphoon | last post by:
Hi, I have report which I need to print 3 times, but would like to have the following headings Customer Copy - Print 1 Accounts Copy - Print 2 File Copy -Print 3 I created a macro to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.