Docverter / docverter

Docverter Server
Other
831 stars 100 forks source link

CSS not included in converted document #50

Open brysonreece opened 7 years ago

brysonreece commented 7 years ago

I'm currently accessing the Docverter API via cURL to convert some documents, like so:

$url = 'http://c.docverter.com/convert';
$fields = array(
    'from' => $_POST["inputButton"],
    'to' => $_POST["outputButton"],
    'input_files[]' => "@/" . $uploadedFilePath,
    'other_files[]' => "@retro.css"
);

//open connection
$ch = curl_init();

//set options
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //needed so that the $result=curl_exec() output is the file and isn't just true/false

//execute POST
$result = curl_exec($ch);

//close connection
curl_close($ch);

//write to file
$convertedFile = fopen($convertedFilePath, 'w');
fwrite($convertedFile, $result);
fclose($convertedFile);

Note: retro.css is located in the same directory as this page and to/from values are determined from the POST values of two separate buttons.

However, no matter what formats I try to convert from/to, the CSS contents of retro.css are never included in the converted document.

peterkeen commented 7 years ago

You need to include the stylesheet parameter set to retro.css unless you're strictly going from HTML to PDF.

See the first example here: https://docverter.com/api/

On Thu, Dec 22, 2016 at 6:44 PM Bryson Reece notifications@github.com wrote:

I'm currently accessing the Docverter API via cURL to convert some documents, like so:

$url = 'http://c.docverter.com/convert';

$fields = array(

'from' => $_POST["inputButton"],

'to' => $_POST["outputButton"],

'input_files[]' => "@/" . $uploadedFilePath,

'other_files[]' => "@retro.css"

);

//open connection

$ch = curl_init();

//set options

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //needed so that the $result=curl_exec() output is the file and isn't just true/false

//execute POST

$result = curl_exec($ch);

//close connection

curl_close($ch);

//write to file

$convertedFile = fopen($convertedFilePath, 'w');

fwrite($convertedFile, $result);

fclose($convertedFile);

Note: retro.css is located in the same directory as this page and to/from values are determine from the POST values of two separate buttons.

However, no matter what formats I try to convert from/to, the CSS contents of retro.css are never included in the converted document.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Docverter/docverter/issues/50, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA2mdMdb4YSmj1vUSGgE80SiirHLL7eks5rKwtMgaJpZM4LUeSK .

brysonreece commented 7 years ago

Changing my $fields array to

$fields = array(
    'from' => $_POST["inputButton"],
    'to' => $_POST["outputButton"],
    'css' => "retro.css", // or @retro.css
    'input_files[]' => "@/" . $uploadedFilePath,
    'other_files[]' => "@retro.css"
);

still fails for HTML -> PDF. My documents gets converted, however no CSS styling is included.

peterkeen commented 7 years ago

You misunderstand. Your first fields array was correct but you need to add another field named stylesheet set to "retro.css". So you'd have from and to set to your post params, input_files[] set to your upload, other_files[] how you have it, and stylesheet = "retro.css"

On Thu, Dec 22, 2016 at 7:09 PM Bryson Reece notifications@github.com wrote:

Changing my $fields array to

$fields = array(

'from' => $_POST["inputButton"],

'to' => $_POST["outputButton"],

'css' => "retro.css", // or @retro.css

'input_files[]' => "@/" . $uploadedFilePath,

'other_files[]' => "@retro.css"

);

still fails. My documents gets converted, how no CSS styling is included.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/Docverter/docverter/issues/50#issuecomment-268918328, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA2mdh7yLDwKctRb_7Y31Jpz1M9HfA4ks5rKxEygaJpZM4LUeSK .

brysonreece commented 7 years ago

Like so?

$fields = array(
    'from' => $_POST["inputButton"],
    'to' => $_POST["outputButton"],
    'input_files[]' => "@/" . $uploadedFilePath,
    'other_files[]' => "@retro.css",
    'stylesheet' => "retro.css"
);

My second example seemed to work when converting Markdown -> PDF, however this example is returning an error when going from Markdown -> PDF and still not including styling when going from HTML -> PDF.