PDF content remains constant while generating pdf using ABCpdf.net

374 views Asked by At

I am trying to generate dynamic pdf using ABCpdf.net in C# .net MVC web application.

        Doc theDoc = new Doc();
        theDoc.Rect.Inset(72, 144);
        string url = System.Web.HttpContext.Current.Request.Url.OriginalString.Replace("GeneratePDFUsingStream", "");

        theDoc.Page = theDoc.AddPage();
        int theID;
        theID = theDoc.AddImageUrl(url,true,1200,true);

        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();
        }

        using (Stream theStream = theDoc.GetStream())
        {
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
            Response.AddHeader("content-length", theStream.Length.ToString());
            long theLen = theStream.Length;
            byte[] theData = new byte[theLen >= 32768 ? 32768 : (int)theLen];
            while (theLen > 0)
            {
                theStream.Read(theData, 0, theData.Length);
                Response.BinaryWrite(theData);
                theLen -= theData.Length;
                if (theLen < theData.Length && theLen > 0)
                    theData = new byte[(int)theLen];
            }
        }
        theDoc.Clear();
        Response.End();

Everything is working fine but the contents of my html is constant in the pdf file.

As per their site recommendation(ABCpdf), i tried following:

Disable cache via code(last parameter-disablecache is set to true: theID = theDoc.AddImageUrl(url,true,1200,true);

Pass a new url each time to AddImageUrl method.

None of these suggestions seems to work. I am not sure if this is due to my browser settings.

Please suggest.

0

There are 0 answers