Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
¿Cómo eliminar los márgenes de un PDF? (Generado usando WeasyPrint)

Estoy intentando renderizar un documento PDF dentro de mi aplicación Flask. Para esto, estoy usando la siguiente plantilla HTML:

 <!DOCTYPE html> <html> <head> <style> @page { margin:0 } h1 { color:white; } .header{ background: #0a0045; height: 250px; } .center { position: relative; top: 50%; left: 50%; -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); text-align:center; } </style> </head> <body> <div class="header"> <div class="center"> <h1>Name</h1> </div> </div> </body> </html>

Sigo obteniendo márgenes blancos en la parte superior y derecha/izquierda de mi sección de encabezado:

¿Cómo eliminar los márgenes de este PDF?

¿Hay alguna manera de eliminarlos?

Editar:

A continuación se muestra el código utilizado para generar el archivo PDF utilizando WeasyPrint en mi aplicación Flask:

 def generate_pdf(id): element = Element.query.filter_by(id=id).first() attri_dict = get_element_attri_dict_for_tpl(element) html = render_template('element.html', attri_dict=attri_dict) pdf = HTML(string=html).write_pdf() destin_loc = app.config['ELEMENTS_FOLDER'] timestamp = dt.datetime.now().strftime('%Y%m%d%H%M%S') file_name = '_'.join(['new_element', timestamp]) path_to_new_file = destin_loc + '/%s.pdf' % file_name f = open(path_to_new_file, 'wb') f.write(pdf) filename = return_latest_element_path() return send_from_directory(directory=app.config['ELEMENTS_FOLDER'], filename=filename, as_attachment=True)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tal vez olvidaste ";" o/y "mm", funciona:

 @page { size: A4; /* Change from the default size of A4 */ margin: 0mm; /* Set margin on each page */ }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!