Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Reason given by maintainers: We recommend directly using a network library such as Requests.

PDFShift Python Package
=======================

This Python package provides a simplified way to interact with the [PDFShift](https://pdfshift.io) API.

## Documentation

See the full documentation on [PDFShift's documentation](https://pdfshift.io/documentation).

## Installation

You should not require this code directly. Instead, just run:

pip install --upgrade pdfshift

or

easy_install --upgrade pdfshift


### Requirements

* Python 2.6+
* [Requests](http://docs.python-requests.org/en/master/)

## Usage

This library needs to be configured with your `api_key` received when creating an account.
Setting it is easy as:

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'
```

### Basic example

#### With an URL

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert('https://www.example.com')

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

#### With inline HTML data:

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

document = open('invoice.html', 'r')
document_content = document.read()
document.close()

binary_file = pdfshift.convert(document_content)
with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Custom CSS

#### Loading CSS from an URL:

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://www.example.com',
css="https://www.example.com/public/css/print.css"
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

#### Loading CSS from a string:

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://www.example.com',
css="a {text-decoration: underline; color: blue}"
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Custom HTTP Headers

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://httpbin.org/headers',
headers={
'X-Original-Header': 'Awesome value',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
}
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Accessing secured pages

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert('https://httpbin.org/basic-auth/user/passwd', auth=('user', 'passwd'))

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Using cookies

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://httpbin.org/cookies',
cookies=[
{'name': 'session', 'value': '4cb496a8-a3eb-4a7e-a704-f993cb6a4dac'}
]
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Adding Watermark (Oh hi Mark!)

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://www.example.com',
watermark={
'image': 'https://pdfshift.io/static/img/logo.png',
'offset_x': 50,
'offset_y': '100px',
'rotate': 45
}
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Custom Header (or Footer)

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://www.example.com',
footer={
'source': '<div>Page {{page}} of {{total}}</div>',
'spacing': '50px'
}
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```

### Protecting the generated PDF

```python
import pdfshift
pdfshift.api_key = '120d8e8a86d2....................'

binary_file = pdfshift.convert(
'https://www.example.com',
protection={
'user_password': 'user',
'owner_password': 'owner',
'no_print': True
}
)

with open('result.pdf', 'wb') as output:
output.write(binary_file)
```


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdfshift-1.0.4.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdfshift-1.0.4-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pdfshift-1.0.4.tar.gz.

File metadata

  • Download URL: pdfshift-1.0.4.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pdfshift-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d9d76a5da536a05bd862f876acfc28767cdeb6c9549591b4dc8bef0171f2f159
MD5 f61405daaf15bd4a5e0eda49c71e936a
BLAKE2b-256 d8d89fe56ab69f82213e7ae5b8f1db5fb5a11059b103f4f4f8ae264e1c423975

See more details on using hashes here.

File details

Details for the file pdfshift-1.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pdfshift-1.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3293b1b33bab33e438b2a73e0cf7b11936c177aa49a9e9b39ab6b887c435a4c6
MD5 e8cca01c8a9519093779b7a6f5e7927c
BLAKE2b-256 eed6681807a26a6f7078fca7dbe41f15f4127399b2731cc45a623bb5bd6043ab

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 files

1.0.0b1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page