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={
'source': 'https://pdfshift.io/static/static/img/logo.png',
'offset_x': 50,
'offset_y': '100px',
'rotate': 45,
'background': true
}
)

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={
'encrypt': 128,
'user_password': 'user',
'owner_password': 'owner',
'no_print': True
}
)

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


Release files for pdfshift 1.0.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdfshift 1.0.0b1
File Size Uploaded Provenance Actions
pdfshift-1.0.0b1.tar.gz 3.3 kB Without provenance Details for pdfshift-1.0.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pdfshift 1.0.0b1
File Interpreter ABI Platform Actions
pdfshift-1.0.0b1-py2.py3-none-any.whl Python 2, Python 3 none any Details for pdfshift-1.0.0b1-py2.py3-none-any.whl

Total release size: 6.7 kB

Release files / pdfshift-1.0.0b1.tar.gz

Download URL pdfshift-1.0.0b1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f5efde9150893583f43b80639de5fc0b2bd6e2f91923ff3b3f4ef5b8d67b52fe
BLAKE2b-256 checksum
How to use checksums
f365d6ca2bc8a73ca025dd8d724676e16b95339a756aeb1f75909f1ac75207ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pdfshift-1.0.0b1-py2.py3-none-any.whl

Download URL pdfshift-1.0.0b1-py2.py3-none-any.whl
Size 3.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
699ddb0c25eff7f59b353aec4e01dae83f6b41eb1ce0320472ce567b0b8f64ea
BLAKE2b-256 checksum
How to use checksums
e63033c379cd329cd5d74e4722691566f32e129501c116db9672ce570cdb8050
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pdfshift 1.0.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0b1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page