Skip to content

Commit 955937b

Browse files
committed
Merge branch 'tables' of github.com:afriedman412/fpdf2 into tables
2 parents 34d2a59 + da2eda9 commit 955937b

32 files changed

+326
-152
lines changed

.all-contributorsrc

+18
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,24 @@
994994
"contributions": [
995995
"code"
996996
]
997+
},
998+
{
999+
"login": "rakesh-nj",
1000+
"name": "Rakesh N J",
1001+
"avatar_url": "https://avatars.githubusercontent.com/u/121295004?v=4",
1002+
"profile": "https://github.com/rakesh-nj",
1003+
"contributions": [
1004+
"doc"
1005+
]
1006+
},
1007+
{
1008+
"login": "Iamrodos",
1009+
"name": "rodos",
1010+
"avatar_url": "https://avatars.githubusercontent.com/u/4513819?v=4",
1011+
"profile": "https://github.com/Iamrodos",
1012+
"contributions": [
1013+
"bug"
1014+
]
9971015
}
9981016
],
9991017
"contributorsPerLine": 7,

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# my files
22
.env
3+
.DS_Store
34

45
# codecov.io
56
coverage.xml

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ in order to get warned about deprecated features used in your code.
1717
This can also be enabled programmatically with `warnings.simplefilter('default', DeprecationWarning)`.
1818

1919
## [2.7.7] - Not released yet
20-
• Tables can now handle multi-index formatting similar to how multi-column formatted is currently implemented.
21-
• Code added to format multi-index and multi-header to match Pandas (repeat labels are now omitted but spaced correctly)
20+
### Added
21+
* SVG importing now supports clipping paths, and `defs` tags anywhere in the SVG file
22+
* Tables can now handle multi-index formatting similar to how multi-column formatted is currently implemented.
23+
* Code added to format multi-index and multi-header to match Pandas (repeat labels are now omitted but spaced correctly)
2224

2325

2426
## [2.7.6] - 2023-10-11

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from fpdf import FPDF
2929
pdf = FPDF()
3030
pdf.add_page()
3131
pdf.set_font('helvetica', size=12)
32-
pdf.cell(txt="hello world")
32+
pdf.cell(text="hello world")
3333
pdf.output("hello_world.pdf")
3434
```
3535

@@ -254,6 +254,8 @@ This library could only exist thanks to the dedication of many volunteers around
254254
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SandraFer"><img src="https://avatars.githubusercontent.com/u/50599578?v=4?s=100" width="100px;" alt="Sandra"/><br /><sub><b>Sandra</b></sub></a><br /><a href="#ideas-SandraFer" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/py-pdf/fpdf2/commits?author=SandraFer" title="Code">💻</a></td>
255255
<td align="center" valign="top" width="14.28%"><a href="https://github.com/navitho"><img src="https://avatars.githubusercontent.com/u/48886097?v=4?s=100" width="100px;" alt="navitho"/><br /><sub><b>navitho</b></sub></a><br /><a href="https://github.com/py-pdf/fpdf2/issues?q=author%3Anavitho" title="Bug reports">🐛</a></td>
256256
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SaiHarshaK"><img src="https://avatars.githubusercontent.com/u/30663807?v=4?s=100" width="100px;" alt="Sai Harsha Kottapalli"/><br /><sub><b>Sai Harsha Kottapalli</b></sub></a><br /><a href="https://github.com/py-pdf/fpdf2/commits?author=SaiHarshaK" title="Code">💻</a></td>
257+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rakesh-nj"><img src="https://avatars.githubusercontent.com/u/121295004?v=4?s=100" width="100px;" alt="Rakesh N J"/><br /><sub><b>Rakesh N J</b></sub></a><br /><a href="https://github.com/py-pdf/fpdf2/commits?author=rakesh-nj" title="Documentation">📖</a></td>
258+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Iamrodos"><img src="https://avatars.githubusercontent.com/u/4513819?v=4?s=100" width="100px;" alt="rodos"/><br /><sub><b>rodos</b></sub></a><br /><a href="https://github.com/py-pdf/fpdf2/issues?q=author%3AIamrodos" title="Bug reports">🐛</a></td>
257259
</tr>
258260
</tbody>
259261
</table>

docs/Development.md

+19
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ pre-commit install
7070
To run tests, `cd` into `fpdf2` repository, install the dependencies using
7171
`pip install -r test/requirements.txt`, and run `pytest`.
7272

73+
You may also need to install [SWIG](https://swig.org/index.html) and [Ghostscript](https://www.ghostscript.com/).
74+
7375
You can run a single test by executing: `pytest -k function_name`.
7476

7577
Alternatively, you can use [Tox](https://tox.readthedocs.io/en/latest/).
@@ -116,9 +118,26 @@ All generated PDF files (including those processed by `qpdf`) will be stored in
116118
last test runs will be saved and then automatically deleted, so you can
117119
check the output in case of a failed test.
118120

121+
### Generating PDF files for testing
119122
In order to generate a "reference" PDF file, simply call `assert_pdf_equal`
120123
once with `generate=True`.
121124

125+
```
126+
import fpdf
127+
128+
svg = fpdf.svg.SVGObject.from_file("path/to/file.svg")
129+
pdf = fpdf.FPDF(unit="pt", format=(svg.width, svg.height))
130+
pdf.add_page()
131+
svg.draw_to_page(pdf)
132+
133+
assert_pdf_equal(
134+
pdf,
135+
"path/for/pdf/output.pdf",
136+
"path/for/pdf/",
137+
generate=True
138+
)
139+
```
140+
122141
## Testing performances
123142

124143
### Code speed & profiling

docs/SVG.md

+2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ Additionally, `cairosvg` offers various options for optimizing the rendering per
190190
- stroke & fill coloring and opacity
191191
- basic stroke styling
192192
- Inline CSS styling via `style="..."` attributes.
193+
- clipping paths
194+
- `defs` tags anywhere in the SVG code
193195

194196
## Currently Unsupported Notable SVG Features ##
195197

docs/Tutorial-bn.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,13 @@ author ([set_author](fpdf/fpdf.html#fpdf.fpdf.FPDF.set_author)) মেথড।
144144

145145
[Jules Verne text](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
146146

147-
পূর্বের টিউটরিয়ালের সাথে এর মূল পার্থক্য হলো
148-
[accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) এবং the set_col মেথডের ব্যবহার।
147+
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
149148

150-
[accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) মেথড ব্যবহার করে, যদি cell পৃষ্ঠার বর্তমান
151-
সর্বনিম্ন লিমিট পার করে, এই মেথড তখন বর্তমান কলাম নাম্বার চেক করে। যখন তা ২ এর ছোট হয় (আমরা একটি পৃষ্ঠাকে তিনটি
152-
কলামে ভাগ করেছি), তখন set_col মেথডটি কল হয়, কলাম নাম্বার বেড়ে যায় এবং লিখার অবস্থান পরবর্তী কলামে চলে যায় যাতে
153-
করে লিখা সেখানেই চলমান থাকে।
149+
English versions:
150+
151+
* [Tuto 4 - Multi Columns](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-4-multi-columns)
152+
* [Documentation on TextColumns](https://py-pdf.github.io/fpdf2/TextColumns.html
154153

155-
যখন ৩য় কলামের সর্বনিম্ন লিমিটে পৌছায়, [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) মেথডটি
156-
রিসেট হয় এবং একটি পেজ ব্রেক এপ্লাই করে আবার প্রথম কলামে চলে যায়।
157154

158155
## টিউটোরিয়াল ৫ - টেবিল তৈরি করা ##
159156

docs/Tutorial-de.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,12 @@ Der Hauptunterschied zur vorherigen Lektion ist die Verwendung der Methode
145145
```
146146

147147
[Erzeugtes PDF](https://github.com/py-pdf/fpdf2/raw/master/tutorial/tuto5.pdf) -
148-
[Länder](https://github.com/py-pdf/fpdf2/raw/master/tutorial/countries.txt)
148+
[Länderdaten](https://github.com/py-pdf/fpdf2/raw/master/tutorial/countries.txt)
149149

150-
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
150+
Das erste Beispiel wird auf die einfachst mögliche Weise umgesetzt, und einfach nur die Daten in die Tabelle eingefügt. Das Ergebnis ist eine sehr schlichte Darstellung, kann aber sehr schnell erzeugt werden.
151151

152-
English versions:
152+
Die zweite Tabelle bringt einige Verfeinerungen: Farben, reduzierte Gesamtbreite, geringere Zeilenhöhe, zentrierter Text, individuelle Spaltenbreiten und rechts justierte Zahlenwerte. Zusätzliche wurden die horizontalen Linien ausgeblendet. Dies wird dadurch erreicht, dass das Argument `borders_layout` einen geeigneten Wert des Enums [`TableBordersLayout`](https://py-pdf.github.io/fpdf2/fpdf/enums.html#fpdf.enums.TableBordersLayout) erhält.
153153

154-
* [Tuto 5 - Creating Tables](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-5-creating-tables)
155-
* [Documentation on tables](https://py-pdf.github.io/fpdf2/Tables.html)
156154

157155
## Lektion 6 - Links erstellen und Textstile mischen ##
158156

docs/Tutorial-es.md

+12-15
Original file line numberDiff line numberDiff line change
@@ -155,33 +155,30 @@ Este ejemplo es una variante del anterior, mostrando cómo poner el texto en mú
155155

156156
[Texto de Julio Verne](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
157157

158-
La diferencia clave con el tutorial anterior es el uso de los métodos
159-
[accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) y set_col.
158+
La diferencia clave respecto al tutorial anterior es el uso del
159+
método [`text_columns`](fpdf/fpdf.html#fpdf.fpdf.FPDF.text_column).
160+
Este recoge todo el texto, posiblemente en incrementos, y lo distribuye entre el número de columnas solicitadas, insertando automáticamente saltos de página según sea necesario. Nota que mientras la instancia de `TextColumns` está activa como gestor de contexto, los estilos de texto y otras propiedades de la fuente pueden cambiarse. Estos cambios estarán contenidos en el contexto. Una vez se cierre, la configuración previa será reestablecida.
160161

161-
Utilizando el método [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break), una vez
162-
la celda cruce el límite inferior de la página, éste comprobará el número de la columna actual. Si
163-
es menor que 2 (decidimos dividir la página en tres columnas) éste invocará al método set_col,
164-
incrementando el número de columna y alterando la posición de la siguiente columna tal que el texto pueda continuar aquí.
165-
166-
Una vez el límite inferior de la tercera columna es alcanzado, el
167-
método [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) se reiniciará y
168-
volverá a la primera columna, desencadenando un salto de página.
169162

170163
## Tutorial 5 - Creando tablas ##
171164

165+
Este tutorial explicará cómo crear dos tablas diferentes,
166+
para demostrar lo que se puede lograr con algunos ajustes simples.
167+
172168
```python
173169
{% include "../tutorial/tuto5.py" %}
174170
```
175171

176172
[PDF resultante](https://github.com/py-pdf/fpdf2/raw/master/tutorial/tuto5.pdf) -
177173
[Archivo de texto con países](https://github.com/py-pdf/fpdf2/raw/master/tutorial/countries.txt)
178174

179-
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
180-
181-
English versions:
175+
El primer ejemplo es alcanzado de la forma más básica posible, alimentando datos a [`FPDF.table()`](https://py-pdf.github.io/fpdf2/Tables.html). El resultado es rudimentario pero muy rápido de obtener.
182176

183-
* [Tuto 5 - Creating Tables](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-5-creating-tables)
184-
* [Documentation on tables](https://py-pdf.github.io/fpdf2/Tables.html)
177+
La segunda tabla trae algunas mejoras: colores, ancho de tabla limitado, altura de línea reducida,
178+
títulos centrados, columnas con anchos personalizados, figuras alineadas a la derecha...
179+
Aún más, las líneas horizontales han sido removidas.
180+
Esto se hizo escogiendo un `borders_layout` entre los valores disponibles:
181+
[`TableBordersLayout`](https://py-pdf.github.io/fpdf2/fpdf/enums.html#fpdf.enums.TableBordersLayout).
185182

186183
## Tutorial 6 - Creando enlaces y combinando estilos de texto ##
187184

docs/Tutorial-fr.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ Cet exemple est une variante du précédent qui montre comment répartir le text
103103

104104
[Extrait de Jules Verne](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
105105

106-
La principale différence avec le tutoriel précédent est l'utilisation des méthodes [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) et `set_col()`.
106+
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
107107

108-
En utilisant la méthode [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break), une fois que la cellule franchit la limite inférieure de la page, elle vérifie le numéro de la colonne actuelle. Si celui-ci est inférieur à 2 (nous avons choisi de diviser la page en trois colonnes), il appelle la méthode `set_col()`, en augmentant le numéro de la colonne et en modifiant la position de la colonne suivante pour que le texte puisse s'y poursuivre.
108+
English versions:
109+
110+
* [Tuto 4 - Multi Columns](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-4-multi-columns)
111+
* [Documentation on TextColumns](https://py-pdf.github.io/fpdf2/TextColumns.html
109112

110-
Une fois que la limite inférieure de la troisième colonne est atteinte, la méthode [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) sera réinitialisée et retournera à la première colonne. Cela déclenchera un saut de page.
111113

112114
## Tuto 5 - Créer des tables ##
113115
Ce tutoriel explique comment créer facilement des tableaux. Deux tableaux différents sont générés, pour illustrer ce qui peut être produit avec de très simples changements.

docs/Tutorial-gr.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ pdf.cell(60, 10, 'Powered by FPDF.', new_x="LMARGIN", new_y="NEXT", align='C')
101101

102102
[Κείμενο του Jules Verne](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
103103

104-
Η κύρια διαφορά από το προηγούμενο παράδειγμα είναι η χρήση των μεθόδων [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) και set_col.
104+
_⚠️ This section has changed a lot and requires a new translation: <https://github.com/py-pdf/fpdf2/issues/267>_
105+
106+
English versions:
105107

106-
Χρησιμοποιώντας την μέθοδο [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break), μόλις το κελί ξεπεράσει το κάτω όριο της σελίδας, γίνεται έλεγχος του αριθμού της τωρινής στήλης. Εάν ο αριθμός αυτός είναι μικρότερος του 2 (επιλέξαμε την κατανομή της σελίδας σε τρεις στήλες) θα κληθεί η μέθοδος set_col, αυξάνοντας τον αριθμό στήλης και αλλάζοντας την θέση της αμέσως επόμενης στήλης έτσι ώστε το κείμενο να συνεχιστεί εκεί.
108+
* [Tuto 4 - Multi Columns](https://py-pdf.github.io/fpdf2/Tutorial.html#tuto-4-multi-columns)
109+
* [Documentation on TextColumns](https://py-pdf.github.io/fpdf2/TextColumns.html
107110

108-
Μόλις φτάσουμε στο το κάτω όριο σελίδας της τρίτης στήλης, η μέθοδος [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) επαναφέρεται και μεταφερόμαστε ξανά πίσω στην πρώτη στήλη όπου πραγματοποιείται αλλαγή σελίδας.
109111

110112
## Μάθημα 5 - Δημιουργία Πινάκων ##
111113

docs/Tutorial-he.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,31 @@ pdf.cell(60, 10, 'Powered by FPDF.', new_x="LMARGIN", new_y="NEXT", align='C')
106106

107107
[Jules Verne text](https://github.com/py-pdf/fpdf2/raw/master/tutorial/20k_c1.txt)
108108

109-
ההבדל העיקרי בין דוגמא זו לקודמת הוא השימוש במתודות [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) וset_col
109+
ההבדל העיקרי מהדוגמא הקודמת הוא השימוש במתודת ה
110+
[`text_columns`](fpdf/fpdf.html#fpdf.fpdf.FPDF.text_column).
111+
היא אוספת את כל הטקסט, ומפזרת אותו על מספר העמודות המבוקש (לפעמים מגדילה אותו), ואוטומטית מעבירה עמוד כשצריך. שימו לב שבזמן שמופע של `TextColumns` פועל כמנהל הקשר (context manager), עיצוב של טקסט ואלמנטים נוספים עשויים להשתנות. שינויים אלה מוכלים בהקשר.
112+
ברגע שהמופע נסגר, ההגדרות הקודמות יוחלו שוב.
110113

111-
ע"י שימוש במתודה [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break), ברגע שתא חורג מהגבול התחתון של הדף, המתודה בודקת את מספר העמודה הנוכחי. אם הוא קטן מ2 (בחרנו לחלק את הדף ל3 עמודות) תיקרא המתודה set_col, שמגדילה את מספר העמודה ומשנה את הפוזיציה של העמודה הבאה כך שהטקסט ימשיך בה.
114+
## 5 - יצירת טבלאות ##
115+
דוגמא זו מסבירה כיצד ניתן ליצור שתי טבלאותשונות, על מנת להדגים מה ניתן להשיג באמצעות התאמות קטנות.
116+
117+
```python
118+
{% include "../tutorial/tuto5.py" %}
119+
```
120+
121+
[תוצר](https://github.com/py-pdf/fpdf2/raw/master/tutorial/tuto5.pdf) -
122+
[Countries CSV data](https://github.com/py-pdf/fpdf2/raw/master/tutorial/countries.txt)
123+
124+
את הטבלא הראשונה ניתן לייצר בדרך הפשוטה ביותר, על ידי הזנת דאטה [`FPDF.table()`](https://py-pdf.github.io/fpdf2/Tables.html).
125+
התוצאה היא בסיסית אבל קלה ומהירה.
126+
127+
The second table brings some improvements: colors, limited table width, reduced line height,
128+
הטבלא השניה מציגה מספר שיפורים: צבעיםת רוחב טבא מוגבלת גובה קווים מופח, כותרות ממורכזות, רוחב עמודות מותאם אישית, יישור לימין...
129+
בנוסף, קווים אופקיים הוסרו.
130+
זה נעשה על ידי בחירת `borders_layout` עם הערכים הזמינים:
131+
[`TableBordersLayout`](https://py-pdf.github.io/fpdf2/fpdf/enums.html#fpdf.enums.TableBordersLayout).
112132

113-
ברגע שהגענו לגבול התחתון של העמודה השלישית, המתודה [accept_page_break](fpdf/fpdf.html#fpdf.fpdf.FPDF.accept_page_break) תאותחל, תחזור לעמודה הראשונה ותיצור מעבר עמוד.
114133

115-
## 5 - יצירת טבלאות ##
116134

117135
```python
118136
{% include "../tutorial/tuto5.py" %}
@@ -151,4 +169,4 @@ English versions:
151169

152170
ניתן גם להשתמש במתודה `()write_html` כדי לשנות סגנונות גופן ולהוסיף קישורים. זהו פארסר של html, שמאפשר להוסיף טקסט, לשנות את הסגנון ולהוסיף קישורים באמצעות html.
153171

154-
</div>
172+
</div>

0 commit comments

Comments
 (0)