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

Url with variables

sergeaubin wrote on 2014-04-29:
Trying to create pdf with the following url and it does not work.

http://gsdc.ca/industriallands/details.php?id=5


thanks
support wrote on 2014-04-30:
Hello,

I tested the URL and the conversion works for me. Could you please provide more details about what exactly does not work? Are you getting any error message?
sergeaubin wrote on 2014-04-30:
Here is the error:

Pdfcrowd Error: convertFile(): '../details.php?id=5' not found Possible reasons: 1. The file is missing. 2. You misspelled the file name. 3. You use a relative file path (e.g. 'index.html') but the current working directory is somewhere else than you expect: 'C:\inetpub\wwwroot\industriallands\pdf' Generally, it is safer to use an absolute file path instead of a relative one.


Here is the core im using:
<?php
require '../pdfcrowd.php';

try
{
// create an API client instance
$client = new Pdfcrowd("***", "***");

// convert a web page and store the generated PDF into a $pdf variable
$pdf = $client->convertFile('../details.php?id=5', $outstream=null);

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

// send the generated PDF
echo $pdf;
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
?>
support wrote on 2014-04-30:
Hello,

convertFile() can convert only HTML files, it can't process a PHP script. You need to use convertURI() instead and pass it an absolute URL. An example:
$pdf = $client->convertURI("http://gsdc.ca/industriallands/details.php?id=5");
sergeaubin wrote on 2014-04-30:
I tried that and i get the following error:

Pdfcrowd Error: [510] Timed out. Can't load the specified URL. List of the resources that can't be loaded: http://gsdc.ca/industriallands/details.php?id=5
support wrote on 2014-05-02:
Hello,

Could please try again now?
sergeaubin wrote on 2014-05-02:
still the same error.
support wrote on 2014-05-02:
Hello,

Could you please run the following code? It works for me, just replace the USERNAME, APIKEY, and OUTDIR placeholders. The code should create out.pdf in OUTDIR. Does it work for you?
require 'pdfcrowd.php';
$client = new Pdfcrowd(USERNAME, APIKEY);

try
{
    $fd = fopen("OUTDIR/out.pdf", 'wb');
    $pdf = $client->convertURI('http://gsdc.ca/industriallands/details.php?id=5', $fd);
    fclose($fd);
}
catch(PdfcrowdException $why)
{
    echo $why;
}
sergeaubin wrote on 2014-05-02:
It created a blank out.pdf file but still same error. Here is the code i have.

<?php

require 'pdfcrowd.php';
$client = new Pdfcrowd("***", "***");

try
{
$fd = fopen("OUTDIR/out.pdf", 'wb');
$pdf = $client->convertURI('http://gsdc.ca/industriallands/details.php?id=5', $fd);
fclose($fd);
}
catch(PdfcrowdException $why)
{
echo $why;
}
?>
support wrote on 2014-05-05:
Hello,

Do you run this code on the gsdc.ca server? If yes, the error can be caused by a restriction in your server configuration.

Can you try to replace "http://gsdc.ca/industriallands/details.php?id=5" with "http://example.com" and let me know if it works for you.
sergeaubin wrote on 2014-05-05:
Yes it's ran from the GSDC.ca server. If i remove the ?id=5 at the end of the url it works fine. Seems like its the url variable that is causing the issue. What config would be wrong on the server?
support wrote on 2014-05-06:
We came across the same situation several times in the past. We were able to convert a web page whereas our user couldn't. It was caused by a restriction in the user's server configuration: An application made a request to our server which in turn back-requested the application. However the application needed to finish with the current request before it could answer the new one and rejected the incoming request.

I recommend that you check your server configuration if there isn't such a restriction. Also check your logs to see what your application returns when our server requests /industriallands/details.php?id=5