0

I want to export my current HTML page after(ng-view is rendered) to a pdf. I am using EvoPDF software to do that but when I am trying to export it the HTML inside ng-view is not coming in the pdf as it. The PDF just contains the header as the header is static element and ng-view is being constructed from XmlHttpRequest.

I tried giving pdfConverter.ConversionDelay = 10; thinking that because of loading time of XmlhttpRequest it is not rendering but still no luck.

I am using HttpModule in .net as backend.

    public void ProcessRequest(HttpContext context)
    {            
        if (context.Request.UrlReferrer != null)
        {
            try
            {
                HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter();
                pdfConverter.ConversionDelay = 10;
                byte[] outPdfBuffer = pdfConverter.ConvertUrl(context.Request.UrlReferrer.ToString());

                context.Response.AddHeader("Content-Type", "application/pdf");

                // Instruct the browser to open the PDF file as an attachment or inline
                context.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=report.pdf; size={1}",
                    "attachment", outPdfBuffer.Length.ToString()));

                context.Response.BinaryWrite(outPdfBuffer);

                // End the HTTP response and stop the current page processing
                context.Response.End();

            }

        }
    }

Can you please let me know how to fix this.

Thanks. Sajesh nambiar

sajesh Nambiar
  • 689
  • 2
  • 10
  • 25
  • Could we have some of the code you are using to call the export ? – sam Nov 06 '14 at 09:35
  • the question is edited with the source code, in the view i just have link to the handler Export to PDF – sajesh Nambiar Nov 06 '14 at 09:39
  • If I understand well how EvoPDF works it exports some html that you provide. The thing is that if you give it your main html page containing the angular app it will only contain the basic html without anything else since angular is not executed. I never used evopdf so it is only pure guessing. – sam Nov 06 '14 at 09:44
  • I see a few options. You could pass the whole page in the request to your server or you can give it your current url, with the angularjs specific url .../#/... but I don't know if the second option would work. – sam Nov 06 '14 at 10:30
  • Maybe this is what you need ? http://stackoverflow.com/questions/817218/get-entire-document-html-as-string – sam Nov 06 '14 at 11:03

1 Answers1

1

There was no problem, it was a CORS issue on my local system thats why the call to fetch the data was failing, everything is working now.

Regards, Sajesh

sajesh Nambiar
  • 689
  • 2
  • 10
  • 25