Plutext

PDF Converter from Python

This page covers invoking the PDF Converter from Python.

The sample code below uses endpoint converter-eval.plutext.com; just change the URL to point at your local install.

To try your docx now, please click here

Using urllib2

Here is sample client code:


import urllib2

# the input docx
file = open('example.docx', 'rb')
data = file.read()

#set up the request
req = urllib2.Request("http://converter-eval.plutext.com:80/v1/00000000-0000-0000-0000-000000000000/convert", data)
req.add_header('Content-Length', '%d' % len(data))
req.add_header('Content-Type', 'application/octet-stream')

# make the request
res = urllib2.urlopen(req)

# write the response to a file
pdf = res.read()
f = open('out.pdf', 'wb')
f.write(pdf)

Using requests

Here is sample client code:


import requests

# the input docx
file = open('example.docx', 'rb')
data = file.read()

#the request
res = requests.post(url='http://converter-eval.plutext.com:80/v1/00000000-0000-0000-0000-000000000000/convert',
                    data=data,
                    headers={'Content-Type': 'application/octet-stream'})


# write the response to a file
f = open('out_other.pdf', 'wb')
f.write(res.content)
    

or alternatively:


import requests

with open('example.docx', 'rb') as docx:
  res = requests.post(url='http://converter-eval.plutext.com:80/v1/00000000-0000-0000-0000-000000000000/convert',
                      data=docx,
                      headers={'Content-Type': 'application/octet-stream'})
  f = open('out_request.pdf', 'wb')
  f.write(res.content)