Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to print a pdf file with document preview and print dialog box so that gives selection of available printers to user in following order:

1 > open pdf with adobe reader or "printPreviewDialog" component in visual studio
so user can have a glance of what he/she is gonna print

2 > then a "printDialog" component automatically shows up and give user the chance of
selecting his/her desired printer(instead of default printer) for printing process

3 > closing adobe reader or preview component after print automatically "IF POSSIBLE"


regards for any help

What I have tried:

my code is :
System.Diagnostics.Process.Start(file);
printDocument1 = new PrintDocument();
printDocument1.DocumentName = file;

printDialog1.Document = printDocument1;
printDialog1.ShowDialog();
Posted
Updated 3-Jul-16 16:56pm
Comments
Leo Chapiro 1-Jul-16 7:55am    
And what is wrong with your solution: any errors?

You're going to have to find and use a 3rd party library to do the printing. The printing facilities built into the .NET Framework will not do you any good because they rely on YOU to provide the code to render each page. Unless you plan on writing your own PDF parser and renderer PrintDocument will do you no good.

All your code did was launch the PDF file in whatever application is registered to open PDF files, usually Acrobat Reader. Then you new'd up a PrintDocument that has nothing whatsoever to do with printing that PDF document.
 
Share this answer
 
Comments
Moosavi S.M. 1-Jul-16 10:07am    
you're right but i got one question!
why visual studio brought "printing" components? are those applicable ? how can i use them?
(actually 3 questions ;) )
Dave Kreskowiak 1-Jul-16 10:31am    
I already said...

They are for when you are supplying all of the code to draw everything you want on each page. If you want to print a text file using the built in methods, you have to supply the code to draw the text on the pages.

Since your code knows NOTHING about parsing and drawing a PDF file, you cannot use the built in components.

Visual Studio does not supply these components. The .NET Framework does.

Launching a Process does not give your code the ability to parse and draw a PDF. You're essentially doing the exact same thing as double-clicking the PDF file yourself to open it. You're telling an outside process to open the PDF and it know how to parse and draw the document. The down side is that your code has just about no control over the process you launched.
Moosavi S.M. 2-Jul-16 9:46am    
ok thanks,
so how can i pars and draw pdf file into pages so i can print them?
Dave Kreskowiak 2-Jul-16 11:08am    
If you want to parse and render a PDF with your own code, you're going to spend a few years writing it.

Find a 3rd party component to do it for you. Just Google for "pdf print component" and start reading.

 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900