Search code examples
asp.net-mvcpdfjquery-mobileabcpdf

ABC Pdf mobile not downloading pdf correctly


I am doing a c sharp MVC project and rendering one of the HTML pages to a PDF. When I call it from the desktop version the PDF downloads automatically without redirecting me. But when I am on my page.mobile.cshtml and press the download pdf button it redirects me to the url for the GetPDF method. If I then refresh that site it downloads the pdf.

What am i doing wrong here, is it some routing settings for the mobile view thats wrong?

This is my getPdf method:

public void getPdf(string snr, string bnr, int bgn)
        {
            Doc theDoc = new Doc();
            theDoc.Clear();
            theDoc.FontSize = 16;

            theDoc.Page = theDoc.AddPage();

            int theID;

            string url = this.Url.Action("TicketPdf", "Home", new { supplierCode = snr, bookingNr = bnr, bgn = bgn }, this.Request.Url.Scheme);

            theID = theDoc.AddImageUrl(url);

            while (true)
            {
                theDoc.FrameRect();
                if (!theDoc.Chainable(theID))
                    break;
                theDoc.Page = theDoc.AddPage();
                theID = theDoc.AddImageToChain(theID);
            }

            for (int i = 1; i <= theDoc.PageCount; i++)
            {
                theDoc.PageNumber = i;
                theDoc.Flatten();
            }

            byte[] theData = theDoc.GetData();
            Response.Clear();
            Response.ContentType = "application/pdf";
            //Response.AddHeader("content-disposition", "inline; filename=ticket.PDF");
            Response.AddHeader("content-length", theData.Length.ToString());

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

            Response.BinaryWrite(theData);
            Response.End();

        }

On both views (Desktop and mobile) i call the it like this:

@Html.ActionLink("Download pdf", "getPDF", new { snr = @bok.CBSupplierId, bnr = @bok.CBBookingCode, bgn = (int)bok.Id })

So when i press the link in desktop view it downloads the PDF without redirecting me. But when i press it in the mobile view that is build with jquery mobile it redirects me to: /Home/getPDF?snr=22558&bnr=IWVY99&bgn=4391


Solution

  • Managed to solve it by adding rel = "external" to the link from the mobile view.