This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Cannot view PDF - authorization required

brr1980 wrote on 2013-01-08:
I am trying to dyncamically generate PDFs from an HTML view in my application using the following code:

$url = base_url() . "profile/" . $payment->user_id . "/voucher/" . $payment->reward_id;

        try {   
            // create an API client instance
            $client = new Pdfcrowd($name, $api_key);
            // convert a web page and store the generated PDF into a $pdf variable
            $pdf = $client->convertURI($url);

            // set HTTP response headers
            header("Content-Type: application/pdf");
            header("Cache-Control: no-cache");
            header("Accept-Ranges: none");
            header("Content-Disposition: inline; filename=\"voucher.pdf\"");

            echo $pdf;

         catch (PdfcrowdException $why) {
            echo "Can't create PDF: ".$why."\n";

When the pages load, the header is set to application/pdf, but I just see a blank white page with the following error:

Authorization Required
This server could not verify that you are authorized to access the document requested. Either you supplied
the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the
credentials required.

Is this some sort of htaccess issue? I am stumped. Please help!
support wrote on 2013-01-08:
It seems the page is password protected. What is the page URL?
brr1980 wrote on 2013-01-08:
The URL is getting generated dynamically based off a user ID number and purchase order. I can access the same page as an admin when I create only a HTML file and don't try to convert it to PDF.
support wrote on 2013-01-09:
You are saying that you can access the page as an admin which indicates that the page is password protected and is not accessible publicly.

If your application uses basic authentication (i.e. using .htaccess) you can specify user/password like this:

The API does not support cookie/session based authentication at this moment so if your application uses this type of authentication then it is not possible to convert such page.
brr1980 wrote on 2013-01-09:
Yes, I'm trying to use this to generate specific vouchers that users could use to claim their purchases. It would only be accessible from logged in users using session based authentication. Bummed to hear this won't work with your API, but thanks for the support.
support wrote on 2013-01-09:
Not sure if this is an option for your but a possible workaround is to make the user specific voucher temporarily accessible (ideally just for the API call) on a public but impossible-to-guess URL.