Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to All,
I have wrote a code for print a .pdf file without showing PrintDialog in windows form application but when the process is start like p.Start() is showing error (No application is associated with the specified file for this operation).

Here is my code :
1.I have download the .pdf file from an Url
2.Then Print that .Pdf file

C#
string UrlName = Url.ToString();
            string DownloadFilePath = @filePath+"\\"+FileName;
            if (File.Exists(DownloadFilePath))
            {
                File.Delete(DownloadFilePath);
            }
            //Downloading file from Http Url
            WebClient myWebClient = new WebClient();
            myWebClient.DownloadFile(UrlName, DownloadFilePath);            
            System.Threading.Thread.Sleep(1000);
            //Code for Print the PDF file
            Process P = new Process();           
            P.StartInfo.FileName = DownloadFilePath; // FileName(.pdf) to print.
            P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; //Hide the window.                        
            P.StartInfo.Verb = "Print";
            PrintDialog pd = new PrintDialog();
            //PrinterSettings setting = new PrinterSettings();           
           
            P.StartInfo.Arguments = pd.PrinterSettings.PrinterName.ToString();
            pd.PrinterSettings.MaximumPage = 1;
            P.StartInfo.CreateNoWindow = true; //!! Don't create a Window.    
            P.Start();
            P.WaitForExit(4000);
            P.CloseMainWindow();
Posted
Updated 28-Jun-12 22:32pm
v2

1 solution

That code won't necessarily print a PDF - it tries to open a PDF using the default application for the extension (PDF).

The error message implies that no such application is registered in your system, so check:
1) That you are outputting the PDF extension with the file name.
2) That your print app is registered as the default handler for PDF files.
 
Share this answer
 
Comments
Kamalkant(kk) 29-Jun-12 4:47am    
I found that code to print the pdf file.Is there any mistake in my code plz help
OriginalGriff 29-Jun-12 4:50am    
It may not be in your code - it is likely to be in your environment instead.
You need to have an application installed to handle PDF files (probably Adobe) - check with where you got the source from and see what they are using.

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