Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi :)

I have a folder with 10 pdfs, and, I whant to know how I can print this 10 pdfs without show the printdialog, for all pdfs, something like this:

C#
public void PrintAllDocuments()
        {
            string[] AllFiles = Directory.GetFiles(@"C:\PDF\", "*.pdf", SearchOption.AllDirectories);

            for (int i = 0; i < AllFiles.Length; i++)
            {
                PrintFile pf = new PrintFile(AllFiles[i]);
                pf.printerName = "HP ???";
                pf.paper = "A4";
                pf.Print();
            }
        }


of course, that is some a sample... but, How I can configure the printer and print the document, witout use the PrintDialog... to open the PDF and print the PDF, how I can do this ??? :(

Thanks for help. :)
Posted

1 solution

add a printDocument control to your form and use that e.g.
C#
this.printDocument1.DocumentName = @"c:\document1.pdf";
this.printDocument1.Print();

See also http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(VS.71).aspx[^] for more details

Ok - everything above here is fine but not for Adobe products - i.e. PDFs.

The following links will be more useful...
Printing pdf files with c#[^]

or
http://bytes.com/topic/c-sharp/answers/247935-pdf-printing-c[^]

and I'm off to have a better look at http://itextpdf.com/[^]
 
Share this answer
 
v2
Comments
URVISH_SUTHAR1 3-Jan-13 9:23am    
yeah, above should work proper
Alexandre Bencz 3-Jan-13 9:40am    
It's simple, but, when I do this, the printer just put out one blank paper... :(
CHill60 3-Jan-13 10:08am    
It's just done the same for me when I use a different printer ... give me a moment or two and I'll try to find out what I've missed out
CHill60 3-Jan-13 10:19am    
I've just updated the solution with some other links - seems it's not that simple to print PDFs!!
Savin Sabu 4-Mar-19 0:20am    
Any solution for this issue.. I also want print the documents without showing the print preview option....

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