You must Sign In to post a response.
  • Category: .NET

    How to print the PDF file without opening the file using .net in Windows service

    How to open the PDF file through windows service without open the file or acrobat.exe in processor.

    Actually we tried the below code it was working when print through windows form with automatically file gets opened, but this is not working when printing by windows service.

    We need to do the same in windows service without opening file. please let me know if any more clarification required in this.

    public string PrintPdf(string filename)
    {
    string FileResult = string.Empty;
    try
    {

    Process p = new Process();
    p.StartInfo = new ProcessStartInfo()
    {
    CreateNoWindow = true,
    UseShellExecute = true,
    Verb = "print",
    FileName = filename,
    WindowStyle = ProcessWindowStyle.Hidden,

    };
    p.Start();
    if (p.HasExited == false)
    {
    p.Kill();
    }
    FileResult = filename;
    }

    catch (Exception Ex)
    {
    FileResult = string.Empty;
    }
    return FileResult;
    }
  • #759100
    Hello Shivasankar,

    Refer the below code :

    string pdfArguments = string.Format(" /t " + "\"" + SavePath + "\\" + _orderNumber + ".pdf\" " + "\"mySharp\"");
    //string pdfPrinterLocation = @"C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe";
    string pdfPrinterLocation = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe";

    ProcessStartInfo newProcess = new ProcessStartInfo(pdfPrinterLocation, pdfArguments);
    newProcess.CreateNoWindow = true;
    newProcess.RedirectStandardOutput = true;
    newProcess.UseShellExecute = false;

    Process pdfProcess = new Process();
    pdfProcess.StartInfo = newProcess;
    pdfProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    pdfProcess.Start();
    pdfProcess.WaitForExit();
    }

    If your code is working in application than the code you have written will alsowork.

    You just have to create the console application and convert it into windows service.

    Put your function in the class and call that function in the Main().

    You are done.
    Enjoy coding.

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "If you can dream it, you can do it."

  • #759104
    we dont have foxitreader.exe. is it any way to do with Acrobatreader.exe or itextSharp?

  • #759107
    Hi Sivashankar.

    For printing pdf files with out opening the file refer below links

    http://forums.asp.net/t/1641436.aspx?Printing+a+PDF+while+using+the+iTextSharp+dll

    http://www.codeproject.com/Questions/858072/printing-a-pdf-file-Directly-without-opening-print

    http://www.c-sharpcorner.com/Blogs/13946/

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/56bfe546-680a-45bb-b904-3c9570a6e6a7/how-to-print-pdf-without-opening-adobe-c

    Regards

    Sridhar.
    DNS Member.
    "Hope for the best.. Prepare for the worst.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #759668
    Hi, another option for you to print PDF with C#. You do not need to open PDF but you're able to set print dialog with code, more details -

    http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Document-Operation/How-to-print-PDF-files-in-C.html

  • #761337
    I am currently loading PDF files as images without viewing them in a service and saving them as TIFF images. I am using leadtools programming tools to support this. I think you can do the printing process in a service using their RasterImagePrinter Class as shown here:
    https://www.leadtools.com/help/leadtools/v19/dh/wi/leadtools.winforms~leadtools.winforms.rasterimageprinter.html

    I hope this helps :)


  • Sign In to post your comments