Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I want print PDF file in server.path(""). Without Preview in page. Only Printing copy.
My asp.net Code here:

C#
 PrinterSettings settings = new PrinterSettings();
            foreach (string printer in PrinterSettings.InstalledPrinters)
            {
                settings.PrinterName = printer;

                if (settings.IsDefaultPrinter)
                {
                    strprintname = printer;
                }
            }

            var fileName = Server.MapPath("download/matrimonimembership.pdf");
            var startInfo = new ProcessStartInfo(fileName);
            string verbToUse = "PrintTo";
            startInfo.Verb = verbToUse;
            startInfo.Arguments = strprintname;
         
            Process p = Process.Start(startInfo);
Response.Write("<script language=javascript>window.alert('success')</script>");
            p.WaitForExit(1000);
            if (p.HasExited == false)
            {
                p.Kill();
            }


This Code to run my local system printed my PDF file . i get message ("Successful")
But. This page hosted my web site . There print PDF click to get Error message

(Error : No application is associated with the specified file for this operation)

Please Help..............me .
Posted
Updated 5-Jun-13 22:07pm
v2

1 solution

Do you have an application installed to handle PDF files (acrobat reader) on the host/client where you are seeing your output?

If yes this should work:

C#
Process.Start(new ProcessStartInfo(filename) { Verb = "PrintTo", UseShellExecute = true, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, Arguments = "\"" + printDialog.PrintQueue.FullName + "\"" });
 
Share this answer
 

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