File: FileAttachments.md

package info (click to toggle)
fpdf2 2.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,828 kB
  • sloc: python: 39,486; sh: 133; makefile: 12
file content (36 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File attachments #

## Embedded file streams

> Embedded file streams [allow] the contents of referenced files to be embedded directly within the body of the PDF
file. This makes the PDF file a self-contained unit that can be stored or transmitted as a single entity.

`fpdf2` gives access to this feature through the method [`embed_file()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.embed_file):

```python
pdf = FPDF()
pdf.add_page()
pdf.embed_file(__file__, desc="Source Python code", compress=True)
pdf.output("embedded_file.pdf")
```

## Annotations

> A file attachment annotation contains a reference to a file, which typically shall be embedded in the
PDF file.

`fpdf2` gives access to this feature through the method [`file_attachment_annotation()`](https://py-pdf.github.io/fpdf2/fpdf/fpdf.html#fpdf.fpdf.FPDF.file_attachment_annotation):

```python
pdf = FPDF()
pdf.add_page()
pdf.file_attachment_annotation(__file__, x=50, y=50)
pdf.output("file_attachment_annotation.pdf")
```

Resulting PDF: [file_attachment_annotation.pdf](https://github.com/py-pdf/fpdf2/blob/master/test/file_attachment_annotation.pdf)

Browser PDF viewers do not usually display embedded files & file attachment annotations,
so you may want to download this file and open it with your desktop PDF viewer in order to visualize the file attachments.

![Screenshot of an embedded file & annotation rendered by Sumatra PDF reader](file_attachment_annotation.png)