forked from pdfrest/pdfrest-api-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown.php
More file actions
33 lines (27 loc) · 1.43 KB
/
Copy pathmarkdown.php
File metadata and controls
33 lines (27 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require 'vendor/autoload.php'; // Require the autoload file to load Guzzle HTTP client.
use GuzzleHttp\Client; // Import the Guzzle HTTP client namespace.
use GuzzleHttp\Psr7\Request; // Import the PSR-7 Request class.
use GuzzleHttp\Psr7\Utils; // Import the PSR-7 Utils class for working with streams.
$upload_client = new Client(['http_errors' => false]);
$upload_headers = [
'api-key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'content-filename' => 'filename.pdf',
'Content-Type' => 'application/octet-stream'
];
$upload_body = file_get_contents('/path/to/file');
$upload_request = new Request('POST', 'https://api.pdfrest.com/upload', $upload_headers, $upload_body);
$upload_res = $upload_client->sendAsync($upload_request)->wait();
echo $upload_res->getBody() . PHP_EOL;
$upload_response_json = json_decode($upload_res->getBody());
$uploaded_id = $upload_response_json->{'files'}[0]->{'id'};
echo "Successfully uploaded with an id of: " . $uploaded_id . PHP_EOL;
$markdown_client = new Client(['http_errors' => false]);
$markdown_headers = [
'api-key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'Content-Type' => 'application/json'
];
$markdown_body = '{"id":"'.$uploaded_id.'","page_break_comments":"on"}';
$markdown_request = new Request('POST', 'https://api.pdfrest.com/markdown', $markdown_headers, $markdown_body);
$markdown_res = $markdown_client->sendAsync($markdown_request)->wait();
echo $markdown_res->getBody() . PHP_EOL;