none
How to Generate a PDF that automatically Prints using iTextSharp RRS feed

  • Question

  • I have already done that Generating of PDF and saved it into C: Drive. What I want to happen now is, After Generating it, it will automatically print on a printer. Do you have any reference or code? 
    Tuesday, October 2, 2018 10:59 AM

Answers

  • You can use the Process to launch your PDF file with the "printto" verb.  This is similar to entering the PDF file name at a command prompt by itself, except that uses the "open" verb.

        public static void PrintPDF(string path)
        {
            Process process = new Process();       	
            process.StartInfo.FileName = path;
            process.StartInfo.Verb = "printto";
    
            process.Start();
    
            // I have to use this in case of Adobe Reader to close the window
    
            process.WaitForInputIdle();
            process.Kill();
        }
    

    If you know the printer name you want, you can pass that in process.StartInfo.Arguments.  As it is, it will print to the default printer.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, October 4, 2018 10:22 PM

All replies

  • This forum is for C# questions and the forums, in general, are for Microsoft products. Please post questions related to third party products like iTextSharp in their forums.

    As for the printing part you can send the saved file to the shell with the print Verb via the Process class and Windows will open the program associated with PDF files and request the print option. Be sure to set UseShellExecute to true otherwise it won't send the verb.


    Michael Taylor http://www.michaeltaylorp3.net


    Tuesday, October 2, 2018 2:41 PM
    Moderator
  • Hi help for my project,

    Thank you for posting here.

    If you want to generate PDF file using iTextSharp, you could refer to the examples below.

    https://www.c-sharpcorner.com/UploadFile/f2e803/basic-pdf-creation-using-itextsharp-part-i/

    https://www.codeproject.com/Articles/277065/Creating-PDF-documents-with-iTextSharp

    What is the printer you want to print PDF file automatically? If you want to use the printer with C# code, you need to contact your provider. The API which you could used to connect to your printer with C# code is very important.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 3, 2018 6:28 AM
    Moderator
  • You can use the Process to launch your PDF file with the "printto" verb.  This is similar to entering the PDF file name at a command prompt by itself, except that uses the "open" verb.

        public static void PrintPDF(string path)
        {
            Process process = new Process();       	
            process.StartInfo.FileName = path;
            process.StartInfo.Verb = "printto";
    
            process.Start();
    
            // I have to use this in case of Adobe Reader to close the window
    
            process.WaitForInputIdle();
            process.Kill();
        }
    

    If you know the printer name you want, you can pass that in process.StartInfo.Arguments.  As it is, it will print to the default printer.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, October 4, 2018 10:22 PM