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

Converting pdf from Drupal

tororebelde wrote on 2010-09-21:
Hi all,

I'm doing some tests to bring a pdf convert functionality to my drupal, but I haven't been able to make it work. If I do a simple test with a simple php script, the API works perfectly, but if I do the function call from drupal, I receive an error which doesn't have sense to me.

I give an example.

This script is outside drupal and works as expected:

<?php
require 'pdfcrowd.php';

function test_print_coupon() {
$pdfapi_username ='xxxx';
$pdfapi_key ='xxxx';

$client = new Pdfcrowd($pdfapi_username, $pdfapi_key);
try
{
$html = "<html><body>In-memory html.</body></html>";
$client->convertHtml($html, fopen('file.pdf', 'wb'));
}
catch(PdfcrowdException $e)
{
echo $e->getMessage();
}
}

test_print_coupon();
?>

And if this function is called from drupal, it return the error "Missing src field.", but the field is sent.

Can you give me a hint o have some idea what's going wrong. After a few hours I feel really confused about this problem.

TIA,
Javier
tororebelde wrote on 2010-09-21:
Finally I found a workaround to made it work. It seems like drupal changes the arg separator, so the url was urlencoded bad.

I changed your pdfcrowd.php library on convertHtml() function to this:

function convertHtml($src, $outstream=null){
$this->fields['src'] = $src;
//$postfields = http_build_query($this->fields);
$postfields = http_build_query($this->fields, '', '&');
$uri = $this->api_prefix . "/pdf/convert/html/";
return $this->http_post($uri, $postfields, $outstream);
}

Now it works like a charm.
support wrote on 2010-09-21:
Thanks for reporting that issue! We will add your change to our library.