-1

I am working on pdf generation, it is successfully implemented using itextsharp.dll. It’s working fine on local environment after publish also. We have our own server at other site

But same code doesn't work on the server,pdf is not generated instead it gives an error: 'The document has no pages.' Initially I thought it is due to no data in document but it works locally with or without data in the document.

I had code implemented as follows to make a web request Is any problem in that ??

try
            {
                var myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strPdfData + "?objpatId=" + patID);

                var response = myHttpWebRequest.GetResponse();
                myHttpWebRequest.Timeout = 900000;
                var stream = response.GetResponseStream();
                StreamReader sr = new StreamReader(stream);
                content = sr.ReadToEnd();
            }
Nikitesh
  • 1,287
  • 1
  • 17
  • 38
Sunil
  • 1
  • 1
  • can you post the code for pdf generation as well?. Also where is the code located. As in same server or different server? – Nikitesh Jul 25 '14 at 11:19
  • yup thanks for reply code is located on different server.Here is my code for it.will you please provide your email id so i can able to send attachment to you because here it is not possible to send you complete code due to more characters in it. – Sunil Jul 26 '14 at 10:59
  • this might be any issue due to cross-domain interaction try to access some other method from the same server. Don't post your entire code just post the required snippets. – Nikitesh Jul 28 '14 at 06:13
  • Hi Nikitesh I got following error - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond – Sunil Jul 28 '14 at 11:52
  • Either the server u r trying to access is not accessible or the service you are calling might be throwing some exception. Check the settings of server where the method is hosted. This link might help you if you are making an ajax call. – Nikitesh Jul 28 '14 at 14:05
  • Thanks nikitesh, I am making the call to the method like this function callmethod(){window.location.href = "@Url.Action("generatePdf", "Admin")?patID=" +@user.PatientId +"&strPass=" + txtPassValue;} – Sunil Jul 30 '14 at 06:43
  • try this http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp – Nikitesh Jul 30 '14 at 08:55
  • I have tried this one but when i go to download the pdf it doesn't show the dialogue box. here is code which i did for download pdf. Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=EMRDetails.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(bytes); Response.End(); – Sunil Jul 30 '14 at 10:30

1 Answers1

0

create a method in the controller:

     [HttpGet]
     public JsonResult GetFile()
     {
       var json = new WebClient().DownloadFile(string address, string fileName);
       //This code is just to convert the file to json you can keep it in file format and send to the view
       dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
       var oc = Newtonsoft.Json.JsonConvert.DeserializeObject<countdata[]>(Convert.ToString(result.countdata));
       return Json(oc, JsonRequestBehavior.AllowGet);
     }

In the view just call this function:

@Url.Action('genPDF','GetFile');
Nikitesh
  • 1,287
  • 1
  • 17
  • 38