Image-to-PDF Conversion

Information

PSPDFKit Server has been deprecated and replaced by Document Engine. All PSPDFKit Server and PSPDFKit for Web Server-Backed licenses will work as before and be supported until 15 May 2024 (we will contact you about license migration). To start using Document Engine, refer to the migration guide. With Document Engine, you’ll have access to robust new capabilities (read the blog for more information).

ℹ️ Note: This requires you to license the Image Documents component.

To convert an image file to PDF, you need to upload your image to PSPDFKit for Web Server-Backed. The following example illustrates this using a PNG file. To create a new document from a PNG file, POST its contents to /api/document:

Request

curl -X POST http://localhost:5000/api/documents \
  -H "Authorization: Token token=<secret token>" \
  -F file=@/path/to/image.png
POST /api/documents HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="file"; filename="image.png"
Content-Type: image/png

<PNG data>
--customboundary--

Response

HTTP/1.1 200 OK
Content-Type: application/json

{
  "data": {
    "document_id": ...,
    "errors": [],
    "sourcePdfSha256": ...,
    "title": "..."
  }
}

PSPDFKit for Web Server-Backed will automatically convert the uploaded file to a PDF and store it for you. Afterward, you can download it as a PDF using the document ID that was previously returned:

Request

GET /api/documents/:document_id/pdf
Authorization: Token token="<secret token>"
$ curl "http://localhost:5000/api/documents/:document_id/pdf \
   -H "Authorization: Token token=<secret token>"

Response

HTTP/1.1 200 OK
Content-Type: application/pdf

<PDF data>

Once an image is uploaded and converted, you can also treat it as you would any other document, using all the features PSPDFKit for Web Server-Backed provides.