0

I am using ABC.PDF to generate pdf from my existing system.It has form authentication mechanism. When i generate pdf it is always generate login page. Here is my function. Please help me ,Thanks inadvanced.

private Doc GeneratePDFPage() {

        var theDoc = new Doc();
        theDoc.HtmlOptions.Engine = EngineType.MSHtml;
        theDoc.HtmlOptions.AddLinks = true;
        var uri = Context.Request.Url.ToString();
        theDoc.HtmlOptions.LogonName = Context.User.Identity.Name;
        theDoc.HtmlOptions.LogonPassword = "7126c198-5aee-47b2-8e6a-09c558892703";

        var html = Response.Filter;

        int theId = theDoc.AddImageUrl(uri);


        //We now chain subsequent pages together. We stop when we reach a page which wasn't truncated
        while (true)
        {
            theDoc.FrameRect();
            if (!theDoc.Chainable(theId))
                break;
            theDoc.Page = theDoc.AddPage();
            theId = theDoc.AddImageToChain(theId);
        }
        ////////////////////////////////////////////////////
        // Set pagenumber
        ////////////////////////////////////////////////////
        theDoc.HtmlOptions.LinkPages();
        //Set the position for the page number

        ////theDoc.Rect.String = "35 30 580 50";
        ////theDoc.Font = theDoc.AddFont("Trebuchet");
        ////theDoc.FontSize = 11;
        ////theDoc.HtmlOptions.UseScript = true;
        int pagenumber = 1;

        //flatten the pages. We can't do this until after the pages have been added because flattening will invalidate our previous ID and break the chain.
        for (int i = 1; i <= theDoc.PageCount; i++)
        {
            theDoc.PageNumber = i;

            //Add page number
            //========================================
            string txt = pagenumber.ToString(CultureInfo.InvariantCulture);
            ////theDoc.Color.String = "169 169 169"; //Dark grey text

            //Positioning depends on if the page is even or odd
            theDoc.VPos = 1.0;
            theDoc.HPos = (i % 2) == 0 ? 0.01 : 0.99;

            //Add the page number
            theDoc.AddText(txt);

            //Add a line above page number
            theDoc.AddLine(21, 55, 590, 55);

            //Flatten page
            theDoc.Flatten();

            //Increase the page number count
            pagenumber++;
        }
        return theDoc;
    }
KDS
  • 99
  • 1
  • 16

1 Answers1

0

Add the location of your page to you webconfig and exclude it from Authorization as below;

  <location path="pdfgenpage.aspx">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
ChrisBint
  • 12,773
  • 6
  • 40
  • 62
  • Thank you for your reply , but i need form authentication. Isnt there any way to generate pdf with authentication mechanism – KDS Nov 29 '12 at 11:39
  • It is hard to find exact solution to convert url content to pdf in ASP.NET form authenticated environment without disabling form authentication.I tried it several days,But useless.I advised to people who are going to buy this product, Please try this with form authentication. The mechanism they are suggesting is insecure as well. Please refer following for more information. [http://codeasp.net/blogs/vivek_iit/microsoft-net/2190/hiqpdf-one-of-the-best-pdf-libraries-in-net] – KDS Dec 05 '12 at 06:44