cancel
Showing results for 
Search instead for 
Did you mean: 

REST API : how download document in PDF

delphine_
Star Contributor
Star Contributor

Hello,

I use the "rest api" in PHP for listing documents and download them. These documents can be in differents formats (doc, pptx, doc, ...), but I want download only in PDF, like button PDF in Document management.

How can I do that ?

Thanks in advance for your answer.

1 REPLY 1

delphine_
Star Contributor
Star Contributor

Solution trouvée !

    $client = new NuxeoPhpAutomationClient('[...]/nuxeo/site/automation');

    $session = $client->getSession($this->user, $this->pass); $answer = $session->newRequest("Blob.ToPDF")
            ->set('input', 'doc:' . $file)
            ->sendRequest();

    if (!isset($answer) OR $answer == false)
        echo '$answer is not set';
    else {
        header('Content-Description: File Transfer');
        header('Content-Type: application/pdf');
        $file = 'fichier.pdf';
        header('Content-Disposition: attachment; filename=' . $file);
        readfile('tempstream');
    }

Si ça peut aider ...