1

我正在发现 PDF 反应器,我想将它用作 Web 服务。为了测试一个文件,我使用 cURL

curl -v -X POST --header "Content-Type:application/xml" http://localhost:9423/service/rest/convert/async -d @test.html

那是对的吗 ?

测试.html:

<html>
<body>
Coucou, je suis terrien.
</body>
</html>

谢谢您的帮助,

塞德里克

编辑#1: 来自上述命令的响应:

* About to connect() to localhost port 9423 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 9423 (#0)
> POST /service/rest/convert/async HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.3.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: localhost:9423
> Accept: */*
> Content-Type:application/xml
> Content-Length: 50
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain
< Date: Tue, 15 Dec 2015 11:47:29 GMT
< Content-Length: 307
< Server: Jetty(9.3.2.v20150730)
< 
* Connection #0 to host localhost left intact
* Closing connection #0
JAXBException occurred : élément inattendu (URI : "", local : "html"). Les éléments attendus sont <{http://webservice.pdfreactor.realobjects.com/}configuration>. élément inattendu (URI : "", local : "html"). Les éléments attendus sont <{http://webservice.pdfreactor.realobjects.com/}configuration>. 
4

1 回答 1

2

通过 cURL 使用 PDFreactor 的 REST API 时,您必须将配置 XML 或 JSON 发送到服务器,其中包括 PDFreactor 和您的文档的配置,如下所述:http://www.pdfreactor.com/product/doc_html/index。 html#d0e688

XML 的示例配置可能如下所示:

配置.xml:

<tns:configuration xmlns:tns="http://webservice.pdfreactor.realobjects.com/">
    <document>&lt;html&gt; &lt;body&gt; Coucou, je suis terrien. &lt;/body&gt; &lt;/html&gt;</document>
</tns:configuration>

然后,您可以调用以下命令:

curl -v -X POST --header "Content-Type:application/xml" http://localhost:9423/service/rest/convert/async.xml -d @config.xml

输出将如下所示:

* About to connect() to localhost port 9423
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 9423
> POST /service/rest/convert/async.xml HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: localhost:9423
> Accept: */*
> Content-Type:application/xml
> Content-Length: 195
> 
> <tns:configuration xmlns:tns="http://webservice.pdfreactor.realobjects.com/">   <document>&lt;html&gt;&lt;body&gt;Coucou, je suis terrien.&lt;/body&gt;&lt;/html&gt;</document></tns:configuration>HTTP/1.1 202 Accepted
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Accept, Content-Length, content-type, Host, User-Agent
< Access-Control-Allow-Methods: GET, PUT, POST, DELETE
< Access-Control-Expose-Headers: Location
< Cache-Control: no-cache
< Date: Wed, 16 Dec 2015 16:34:19 GMT
< Location: http://localhost:9423/service/rest/progress/c2a58dbd-ef9d-4b79-87d9-079c139fe9ed
< Content-Length: 0
< Server: Jetty(9.3.2.v20150730)
* Connection #0 to host localhost left intact
* Closing connection #0

“Location”响应标头包含可用于检索转换进度的 URL,因此您可以使用以下方式检索进度(ID 当然会有所不同):

curl -v http://localhost:9423/service/rest/progress/c2a58dbd-ef9d-4b79-87d9-079c139fe9ed

这将返回转换进度,如果转换已完成,“Location”响应头将包含一个新的 URL 来检索文档。您可以使用“.pdf”检索 PDF 二进制数据或“.xml”检索包含 PDF 作为 base64 编码字符串、文档页数等的 XML 数据。

curl -v http://localhost:9423/service/rest/document/c2a58dbd-ef9d-4b79-87d9-079c139fe9ed.pdf
于 2015-12-16T17:09:02.127 回答