issue159:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
issue159:python [2020/08/03 08:11] – d52fr | issue159:python [2020/08/05 23:09] – d52fr | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
It's rather old, and there hasn't been much activity recently. In fact, the last update to the repository was about 3 years ago.** | It's rather old, and there hasn't been much activity recently. In fact, the last update to the repository was about 3 years ago.** | ||
- | PyFPDF est une bibliothèque qui vous permet de générer des documents PDF osus Python. Elle a été portée à partir de FPDF (« Free » -PDF) dans une bibliothèque en PHP. Le dépôt est sur github à https:// | + | PyFPDF est une bibliothèque qui vous permet de générer des documents PDF sous Python. Elle a été portée à partir de FPDF (« Free » -PDF) dans une bibliothèque en PHP. Le dépôt est sur github à https:// |
- | certaines des fonctionnalités que cette bibliothèque fournit sont la possibilité d' | + | certaines des fonctionnalités que cette bibliothèque fournit sont la possibilité d' |
Elle est assez ancienne et il n'y a pas eu beaucoup d' | Elle est assez ancienne et il n'y a pas eu beaucoup d' | ||
Ligne 42: | Ligne 42: | ||
Now we'll break down the program. After we import the FPDF library, we instantiate the library, by calling pdf=FPDF(), with the default options.** | Now we'll break down the program. After we import the FPDF library, we instantiate the library, by calling pdf=FPDF(), with the default options.** | ||
+ | |||
+ | Plongeons-nous dedans et créons notre premier exemple de programme. Saisissez ce programme dasn votre IDE favori et sauvegardez-le sous « ftest1.py ». Plus tard, nous le modifierons un peu. | ||
+ | |||
+ | from fpdf import FPDF | ||
+ | |||
+ | pdf = FPDF() | ||
+ | pdf.add_page() | ||
+ | pdf.set_font(' | ||
+ | pdf.cell(40, | ||
+ | pdf.output(' | ||
+ | |||
+ | Maintenant, décomposons le programme, Après l' | ||
**Next, we add a page. These are pretty much the first two things that you have to do before you can do anything else. | **Next, we add a page. These are pretty much the first two things that you have to do before you can do anything else. | ||
Ligne 53: | Ligne 65: | ||
orientation = (p: | orientation = (p: | ||
- | | + | units = (pt:point, mm: |
- | format = (A3, A4, A5, Letter, Legal) (default is A4) (see below)** | + | format = (A3, A4, A5, Letter, Legal) (default is A4) (see below)** |
+ | |||
+ | Ensuite, nous ajoutons une page. Ce sont pratiquement les deux premières choses que vous devez faire avant que vous puissiez faire autre chose. | ||
+ | |||
+ | Ensuite, nous paramétrons la police par défaut pour la page ; après, nous utilisons la méthode cell pour imprimer un simple texte et, alors, nous appelons la méthode output pour créer le fichier pdf lui-même. | ||
+ | |||
+ | Quand nous avons créé l' | ||
+ | |||
+ | pdf = FPDF(orientation, | ||
+ | |||
+ | où : | ||
+ | |||
+ | orientation = (p: | ||
+ | |||
+ | units = (pt:point, mm: | ||
+ | |||
+ | | ||
**If you need a custom page size, you can send a tuple with the width and height in the given units. If you are using Portrait mode, the order should be (width, height), but if you are using landscape, it should be (height, width). Also, try as I might, I couldn' | **If you need a custom page size, you can send a tuple with the width and height in the given units. If you are using Portrait mode, the order should be (width, height), but if you are using landscape, it should be (height, width). Also, try as I might, I couldn' | ||
Ligne 69: | Ligne 97: | ||
• Symbol | • Symbol | ||
• ZapfDingbats** | • ZapfDingbats** | ||
+ | |||
+ | Si vous avez besoin d'une taille de page personnalisée, | ||
+ | |||
+ | Ensuite, nous réglons la police à utiliser. L' | ||
+ | |||
+ | < | ||
+ | |||
+ | La méthode set-font vous permet de spécifier la police à utiliser pour les lignes suivantes du texte à restituer. Cependant, ce n'est pas aussi libre que vous pourriez le penser. Il y a cinq polices normales utilisables qui sont pré-définies (sauf si vous ajoutez « add_font » en premier). Les voici : | ||
+ | • Courier (largeur fixe) | ||
+ | • Helvetica or Arial | ||
+ | • Times | ||
+ | • Symbol | ||
+ | • ZapfDingbats | ||
+ | |||
**These 5 fonts provide fixed width, sans-serif, serif, and two symbolic fonts. The font family parameter is case insensitive as well as the font style. Those styles can be: | **These 5 fonts provide fixed width, sans-serif, serif, and two symbolic fonts. The font family parameter is case insensitive as well as the font style. Those styles can be: | ||
Ligne 82: | Ligne 124: | ||
If you want to use a special font for some reason, outside of the standard font set provided, you can use the add_font method. However, it is fairly difficult, so we'll discuss it in a future article. In the meantime, you can look at the documentation to see how to do it.** | If you want to use a special font for some reason, outside of the standard font set provided, you can use the add_font method. However, it is fairly difficult, so we'll discuss it in a future article. In the meantime, you can look at the documentation to see how to do it.** | ||
- | **Now, we'll take a look at the cell method, that allows you to place the text to be rendered. This method will print a rectangular area with optional borders, possibly background and foreground colors, and the character string. The text can be aligned to the right or left or can be centered. When the call is finished, the current position moves to the right or to the next line, depending on a parameter passed, and allows for an optional link to be attached to the text. The format of the method parameters is fairly comprehensive, | + | Parmi ces 5 polices sont fournies une à largeur fixe, une sans-serif, une serif et deux polices symboliques. Le paramètre des familles de polices est insensible à la casse de même qu'au style de police. Ces styles peuvent être : |
+ | B : gras | ||
+ | I : italique | ||
+ | U : sousligné | ||
+ | vide : normal | ||
+ | |||
+ | Note : si vous voulez changer la taille de la police dans le document, changer la famille ou le style, vous pouvez appeler : | ||
+ | |||
+ | fpdf.set_font_size(size) | ||
+ | |||
+ | Si vous voulez utiliser une police spéciale pour un raison quelconque, en dehors de u lot de polices fournies en standard, vous pouvez utiliser la méthode add_font. Cependant, elle est assez compliquée, | ||
+ | |||
+ | **Now, we'll take a look at the cell method, that allows you to place the text to be rendered. This method will print a rectangular area with optional borders, possibly background and foreground colors, and the character string. The text can be aligned to the right or left or can be centered. When the call is finished, the current position moves to the right or to the next line, depending on a parameter passed, and allows for an optional link to be attached to the text. The format of the method parameters is fairly comprehensive, | ||
fpdf.cell(w, | fpdf.cell(w, | ||
| | ||
+ | |||
+ | Maintenant, nous allons regarder la méthode cell, qui vous permet de placer le texte à restituer. cette méthode imprimera une zone rectangulaire avec des bordures optionnelles, | ||
+ | |||
+ | fpdf.cell(w, | ||
+ | |||
+ | Regardons chacun des paramètres un peu plus en détail... | ||
**w: Cell width. If this value is 0, the cell will extend to the right margin. | **w: Cell width. If this value is 0, the cell will extend to the right margin. | ||
Ligne 106: | Ligne 166: | ||
Finally, we call pdf.output to render the file and save it as the filename specified (which is the ‘F’ parameter). There are other parameters that you can research in the document.** | Finally, we call pdf.output to render the file and save it as the filename specified (which is the ‘F’ parameter). There are other parameters that you can research in the document.** | ||
+ | |||
+ | w - largeur de la cellule. Si cette valeur est 0, la cellule s' | ||
+ | |||
+ | h - hauteur de la cellule. La valeur par défaut est 0. | ||
+ | |||
+ | txt - la chaîne à imprimer. | ||
+ | |||
+ | border - 0 : pas de bordure. 1 ; cadre (ou une chaîne contenant quelles sont les lignes du cadre à restituer) | ||
+ | |||
+ | ln - 0 : à droite. 1 : au début de la ligne suivante. 2 : en dessous. | ||
+ | |||
+ | align - « L » : alignement à gauche, « C » : centré, « R » : alignement à droite | ||
+ | |||
+ | fill - True : fond coloré. False : transparent. Valeur par défaut = False | ||
+ | |||
+ | link - URL ou indentifiant retourné par add_link() | ||
+ | |||
+ | Enfin, nous appelons pdf.output pour un rendu du fichier et sa souvegarde sous le nom de fichier spécifié (qui est le paramètre « F »). Il y a d' | ||
**Once the program is done, you can open it with your default PDF viewer. It should look something like the image above. | **Once the program is done, you can open it with your default PDF viewer. It should look something like the image above. | ||
Ligne 118: | Ligne 196: | ||
Notice that we added all the parameters for the cell method. In this version, we will be adding a border with transparent fill, make the text centered, have the cell go from the far left extending to the far right of the page, set the next text line to be on the line below, and added a link to the Full Circle Magazine website, when you click on the text. We also changed the output file name.** | Notice that we added all the parameters for the cell method. In this version, we will be adding a border with transparent fill, make the text centered, have the cell go from the far left extending to the far right of the page, set the next text line to be on the line below, and added a link to the Full Circle Magazine website, when you click on the text. We also changed the output file name.** | ||
+ | |||
+ | Une fois le proramme terminé, vous pouvez l' | ||
+ | |||
+ | Maintenant, nous regarderons l' | ||
+ | |||
+ | pdf.cell(0, 10, 'Hello Full Circle Magazine!', | ||
+ | |||
+ | 1, | ||
+ | |||
+ | pdf.output(' | ||
+ | |||
+ | Notez que nous avons ajouté tous les paramètres à la méthode cell. Dans cette version, nous ajouterons une bordure avec un remplissage transparent, | ||
**Save the program as “test1a” and try it again (see image below). | **Save the program as “test1a” and try it again (see image below). |
issue159/python.txt · Dernière modification : 2020/08/09 09:48 de auntiee