2017-08-03 1 views
0

Informations générales

J'ai le code Python suivant que je veux utiliser pour générer un fichier pdf. Il utilise le pdfkit library.Comment afficher une ligne de bas de page au-dessus du pied de page en utilisant la bibliothèque pdfkit en python?

import pdfkit    # import python module 

if __name__=="__main__": 


    options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

    ##this is the path of the whkhtmltopdf.exe in order for the library to 
    ##work on a Windows OS 
    path_wkthmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe' 
    config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf) 

    pdfkit.from_url('http://google.com', 'Report.pdf',options=options,configuration=config)) 

Le PDF résultant est la suivante. Tout ce dont j'ai besoin est simplement une ligne au-dessus de ceci est un pied de page. The Resulting PDF

Selon le site suivant, je peux ajouter une ligne de bas de page au-dessus du pied de page en utilisant l'attribut footer-line mais je ne comprends pas la syntaxe sur la façon de le mettre en œuvre en python

https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

la question en bref

Comment puis-je modifier l'attribut options pour inclure footer-line?

options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

Répondre

0

Apparemment, vous ajoutez simplement l'attribut et passez un paramètre vide

donc à l'options attribut que vous venez d'ajouter 'footer-line':'' Il est reformulé comme suit

 options = { 
     'page-size': 'Letter', 
     'margin-top': '0.5in', 
     'margin-right': '0.75in', 
     'margin-bottom': '0.5in', 
     'margin-left': '0.75in', 
     'encoding': "UTF-8", 
     'footer-left': "This is a footer", 
     'footer-line':'', 
     'footer-font-size':'7', 
     'footer-right': '[page] of [topage]', 

     'custom-header' : [ 
      ('Accept-Encoding', 'gzip') 
     ], 
     'no-outline': None 
    } 

S'il y a une meilleure façon de le faire s'il vous plaît laissez-moi savoir