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

C#
protected void btnExportToExcel_Click(object sender, EventArgs e)
        {
            //Way1();

            //Way2();

            WorkingWay3();
            WorkingWay3();
        }



C#
private void WorkingWay3()
        {

            HtmlToPdf("http://localhost:32370/User/PerformancePDF.aspx", "D:\\New.pdf");

        }



private void HtmlToPdf(string website, string destinationFile)
        {

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.UseShellExecute = false;

            startInfo.RedirectStandardOutput = true;

            startInfo.RedirectStandardInput = true;

            startInfo.RedirectStandardError = true;

            startInfo.CreateNoWindow = true;

            startInfo.FileName = "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe";
            startInfo.Arguments = website + " " + destinationFile;
            Process myProcess = Process.Start(startInfo);
            myProcess.WaitForExit();

            myProcess.Close();

            Response.Clear();

            Response.AddHeader("content-disposition", "attachment;filename=abc.pdf");

            Response.ContentType = "application/pdf";

            Response.WriteFile(destinationFile);
            Response.End();

        }


Above is my code , i am trying to generate multiple pdf files , as my requirement is there can be multiple pdf with differnt differnt page , i tried to call same method twice , but it gets called only once , and give me single pdf document ..

I also tried to use for loop by giving differnt website path , but again it gets called only once , in this i comment last line that is respond.end to debug .. but then it calls multiple times for loop , but at last only single pdf generated ..

Please suggest
Posted
Comments
Sinisa Hajnal 13-Oct-14 3:20am    
Single PDF is generated simply because you show no mechanism for changing the target file name. It is always D:\\New.pdf...you should change this and you'll probably get the files you need.
Torakami 14-Oct-14 2:53am    
HtmlToPdf("http://localhost:32370/User/PerformancePDF.aspx", "D:\\New.pdf");
HtmlToPdf("http://localhost:32370/User/Objectives.aspx?ChkMyTeam=YES&id=12", "D:\\objnew.pdf");

this is what i tried now , chnages the location as well as path for seconf pdf as well .. but only first pdf get executed ..
Sinisa Hajnal 14-Oct-14 4:04am    
They you likely have some silent exception which skips the second one. Wrap HtmlToPDF in Try...Catch and print out any exception you get.
Torakami 14-Oct-14 7:01am    
hii , there is no exception .. its because ..reposnse.end() which is skiping my next execution of the program , perhaps i ned to think about something else

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