GithubHelp home page GithubHelp logo

kozea / weasyprint Goto Github PK

View Code? Open in Web Editor NEW
6.7K 134.0 645.0 33.58 MB

The awesome document factory

Home Page: https://weasyprint.org

License: BSD 3-Clause "New" or "Revised" License

Python 97.17% HTML 0.89% CSS 1.94%
python css pdf html converter weasyprint

weasyprint's Introduction

The Awesome Document Factory

WeasyPrint is a smart solution helping web developers to create PDF documents. It turns simple HTML pages into gorgeous statistical reports, invoices, tickets…

From a technical point of view, WeasyPrint is a visual rendering engine for HTML and CSS that can export to PDF. It aims to support web standards for printing. WeasyPrint is free software made available under a BSD license.

It is based on various libraries but not on a full rendering engine like WebKit or Gecko. The CSS layout engine is written in Python, designed for pagination, and meant to be easy to hack on.

WeasyPrint has been created and developed by Kozea (https://kozea.fr/). Professional support, maintenance and community management is provided by CourtBouillon (https://www.courtbouillon.org/).

Copyrights are retained by their contributors, no copyright assignment is required to contribute to WeasyPrint. Unless explicitly stated otherwise, any contribution intentionally submitted for inclusion is licensed under the BSD 3-clause license, without any additional terms or conditions. For full authorship information, see the version control history.

weasyprint's People

Contributors

ariofrio avatar aschmitz avatar azhar316 avatar bot-jonas avatar cleitner avatar colinkinloch avatar elpaso avatar fdeslandes avatar felixschwarz avatar graingert avatar grewn0uille avatar hughsw avatar jdus avatar kygoh avatar le-stagiaire avatar lize avatar luciend avatar malnajdi avatar mbarkhau avatar mwedl avatar plaes avatar randomstuff avatar rianmcguire avatar sahilrl avatar simonsapin avatar smylers avatar timoramsauer avatar tontyna avatar vagnernico avatar xavidotron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

weasyprint's Issues

Support short meta charset tag

Hi !

Unless I am mistaken, I think weasyprint des not support the short meta charset tag:

<meta charset="utf-8">

But works fine with the complete one:

<meta http-equiv="Content-Type" content="Type=text/html; charset=utf-8">

Most of html5 website use the short one.
Because it is simpler and I think enought according to the specification.

Thanks for sharing weasyprint,
Thomas.

Links in generated PDF

Hi!

I really find the cleanliness of the generated .pdf's astounding! Well done!

Is there a way to generate pdf's with links either reffering to other places in the document or externally (http://...)?
If not, is that something that's on the roadmap?

Table cell widths (sometimes) being ignored

Have a look at http://www.stripey.com/demo/weasyprint/table_cell_width.html in a web browser and its rendering in WeasyPrint (version 0.16): http://www.stripey.com/demo/weasyprint/table_cell_width.pdf

All the tables have width: 100%.

In the second table WeasyPrint ignores % widths (applied to both columns, just to make sure), using the default widths for the content. Browsers (I checked Firefox and Chromium) behave as expected.

In the third table WeasyPrint ignores an em width setting on the left column, again using the default. Browsers behave as expected here: resizing the window only changes the (unspecified) width of the right column.

The fourth table shows the only way I've found of making WeasyPrint take note of cell widths: specifying an em width on each column. Despite the use of em, these are effectively proportional widths (obviously it isn't possible to use those specified widths while also having the entire table width add up to the required 100% of the page width). WeasyPrint matches browsers here: 10em out of a total of (10em + 15em) gives 40% to the first column and 60% to the second; browsers render this the same as the second table, with those % widths specified.

So it seems that percentage widths are ignored entirely, and other units' widths only have any effect if they're specified for every column; I'm not sure if that's two independent bugs or just one — let me know if you want me to split this into two separate issues.

Allow page breaks in floats, absolute blocks, table-cells

Floated elements that don't fit on the current page simply fall off the bottom, rather than being placed on the next page.

Here's a handy long list of floated elements to demonstrate the problem: http://www.stripey.com/demo/weasyprint/float_off_bottom.html

Look at it in Firefox and do ‘Print Preview’. You should see that there's a page break, with the list being continued on page 2. Similarly if you print from Chromium.

But WeasyPrint generates this file, where the elements simply run off the bottom of the first page: http://www.stripey.com/demo/weasyprint/float_off_bottom.pdf

Line height and margin applied incorrectly

<head>
    <style>
        .numbered {
            font-family: Verdana, Arial;
            margin-left: 9em;
        }
        .numberspan {
            float: left;
            margin-left: -4em;
        }
    </style>
</head>
<body>
    <div class="numbered"><span class="numberspan">1.1.1.</span><span>The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.</span></div>
</body>

Chrome renders it as:
Chrome rendering

WeasyPrint renders it as:
WeasyPrint rendering

cannot import name properties

I'm trying to use WeasyPrint in my virtualenv. I followed the Homebrew steps from the installation instructions, but I get an error while trying to generate a simple PDF:

Traceback (most recent call last):
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/ldiqual/Documents/Projects/app-django/backend/views/admin/actions.py", line 87, in handle_admin_actions
    return generate_contract(request, vendor)
  File "/Users/ldiqual/Documents/Projects/app-django/backend/utils/contract_generator.py", line 28, in generate_contract
    pdf = render_to_pdf(request, "backend/steps/contract/contract.html", context_dict)
  File "/Users/ldiqual/Documents/Projects/app-django/backend/utils/common.py", line 61, in render_to_pdf
    weasyprint.HTML(string=html).write_pdf(target=result)
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/weasyprint/__init__.py", line 98, in __init__
    from .html import find_base_url
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/weasyprint/html.py", line 22, in <module>
    from .formatting_structure import boxes
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/weasyprint/formatting_structure/boxes.py", line 63, in <module>
    from ..css.computed_values import ZERO_PIXELS
  File "/Users/ldiqual/Documents/Projects/app-django/app_env/lib/python2.7/site-packages/weasyprint/css/__init__.py", line 51, in <module>
    from . import properties
ImportError: cannot import name properties

The error comes from weasyprint/css/__init__.py:

import tinycss
import cssselect
import lxml.etree

from . import properties # <=== This line
from . import computed_values
from .validation import preprocess_declarations

CSS-selector specificity calculation does not match Firefox/WebKit

CSS-selector specificity isn't compatible with Firefox and WebKit. Following example shows red box on both engines, but in WeasyPrint the box is blue:

<style>
#id_one {
    background: blue;
}
.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c.c {
    background: red;
}
</style>
<div id="id_one" class="c"></div>

Full-blown example with extra info at https://gist.github.com/3368120.

Crash: AttributeError: 'BlockBox' object has no attribute 'index'

WeasyPrint crashes on this input: http://www.stripey.com/demo/weasyprint/float_dd_ul_crash.html

I've checked with version 0.17. The stack trace is below.

It works fine if the height of the spacer <div> is either reduced to 6.5in or increased to 6.8in.

Traceback (most recent call last):
File "/usr/local/bin/weasyprint", line 9, in
load_entry_point('WeasyPrint==0.17', 'console_scripts', 'weasyprint')()
File "/usr/local/lib/python2.7/dist-packages/weasyprint/main.py", line 141, in main
getattr(html, 'write_' + format_)(output, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/init.py", line 159, in write_pdf
return self.render(stylesheets).write_pdf(target, zoom)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/init.py", line 131, in render
return Document._render(self, stylesheets, enable_hinting)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/document.py", line 251, in _render
return cls([Page(p, enable_hinting) for p in page_boxes])
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/init.py", line 52, in layout_document
pages = list(make_all_pages(context, root_box))
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py", line 539, in make_all_pages
context, root_box, page_type, resume_at, content_empty)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/pages.py", line 504, in make_page
positioned_boxes, positioned_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 59, in block_level_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 87, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 402, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 59, in block_level_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 87, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 402, in block_container_layout
adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 59, in block_level_layout
absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 87, in block_box_layout
page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 445, in block_container_layout
new_children, absolute_boxes, fixed_boxes)
File "/usr/local/lib/python2.7/dist-packages/weasyprint/layout/blocks.py", line 653, in find_earlier_page_break
resume_at = (children[index].index, None)
AttributeError: 'BlockBox' object has no attribute 'index'

[bug][Python3.2][Archlinux] IndexError: pop from empty list

Hello,

First of all, thanks for the great work !
I installed Weasyprint with the AUR package, and I am getting this error while trying to generate a pdf for a text-only page (the only css is a class for page-break) :

weasyprint http://localhost:1291/pdf/Hisdesat test.pdf
Traceback (most recent call last):
  File "/usr/bin/weasyprint", line 9, in <module>
    load_entry_point('WeasyPrint==0.11', 'console_scripts', 'weasyprint')()
  File "/usr/lib/python3.2/site-packages/weasyprint/__main__.py", line 79, in main
    getattr(html, 'write_' + format_)(output, stylesheets=args.stylesheet)
  File "/usr/lib/python3.2/site-packages/weasyprint/__init__.py", line 124, in write_pdf
    return document.write_pdf(target)
  File "/usr/lib/python3.2/site-packages/weasyprint/document.py", line 171, in write_pdf
    pdf.write_pdf_metadata(self, file_obj)
  File "/usr/lib/python3.2/site-packages/weasyprint/pdf.py", line 420, in write_pdf_metadata
    bookmarks, links = gather_metadata(document)
  File "/usr/lib/python3.2/site-packages/weasyprint/pdf.py", line 416, in gather_metadata
    return process_bookmarks(bookmarks), resolved_links_by_page
  File "/usr/lib/python3.2/site-packages/weasyprint/pdf.py", line 319, in process_bookmarks
    k += 1 + level_shifts.pop()
IndexError: pop from empty list

I need more data, do tell me

Implement `target-counter` to create table of contents

I'd like to automatically create a table of contents in my document.
I am thinking of using a small piece of Javascript....
But I have a feeling WeasyPrint doesn't process javascript.. ?
Or are there other ways of doing this ?

Sander.

Content in @bottom is cut off

When using @bottom-left @bottom-right etc, the page produced is larger than A4, and then the only way to see everything on a page is to print 'fit-to-page' which produces exceptionally large margins.

include downsampling of images in weasyprint

Hello Weasyprint Developers,

Thank you for this great software. I use weasyprint to generate PDFs from HTML and find that it is is a great asset for generating reports, however I would like to request a feature: the ability to downsample images within a PDF to reduce the output file size.

Following Weasyprint I will often downsample the PDF using a variation of the ghostscript script on this Stack Overflow post and can reduce my file size from 40MB file to a5MB. This is due, of course, to the presence of a number of large images in the source HTML. I could make smaller versions of these but would prefer to downsample only at the last step. So while I can get around this issue without to much effort, I think incorporation of a downsampling feature into weasyprint would be desirable/useful.

thanks,
zach cp

height for table

height works like min height for table with fixed layout but it's not working with % in weasyprint. With cm it's ok.
kind of the same with width.

Zapfino typface (font) not correctly rendered

zapfino_sm
Screen shot 2013-03-15 at 17 53 40

On OS X 10.6.8, Firefox, TextEdit and others render the word "Zapfino" in the typeface Zapfino as in the first attached image. However, WeasyPrint renders it as in the second attached image.

My understanding is that in this particular case, Firefox, TextEdit, etc, are honouring Zapf's intentions, and that WeasyPrint is not.

min-width and max-width being ignored

min-width and max-width seem to be being ignored; the changelog says they've been supported since version 0.8.

See: http://www.stripey.com/demo/weasyprint/min_max-width.html and http://www.stripey.com/demo/weasyprint/min_max-width.pdf

The min-width should be stretching the second paragraph to be the same width as the width does one the first. And the max-width on the final paragraph should be constraining it like width does on the fourth one.

That's what happens in browsers, but in WeasyPrint (I checked with version 0.16), the min-width and max-width are having no affect.

Crash: ZeroDivisionError with dashed lines

This HTML file crashes WeasyPrint (0.17) with a division-by-zero error: http://www.stripey.com/demo/weasyprint/dash.html

It works as intended if the border style is changed from dashed to dotted.

I can only get the crash to occur when the bordered element breaks across pages and contains a floated element, so possibly this is related to Issue #36.

Here's the stack trace:

Traceback (most recent call last):
  File "/usr/local/bin/weasyprint", line 9, in <module>
    load_entry_point('WeasyPrint==0.17', 'console_scripts', 'weasyprint')()
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/__main__.py", line 141, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/__init__.py", line 159, in write_pdf
    return self.render(stylesheets).write_pdf(target, zoom)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/document.py", line 393, in write_pdf
    page.paint(context, scale=scale)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/document.py", line 226, in paint
    draw_page(self._page_box, cairo_context, self._enable_hinting)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 61, in draw_page
    draw_stacking_context(context, stacking_context, enable_hinting)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 167, in draw_stacking_context
    draw_stacking_context(context, child_context, enable_hinting)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 137, in draw_stacking_context
    context, stacking_context.page, block, enable_hinting)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 67, in draw_box_background_and_border
    draw_border(context, box, enable_hinting)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 334, in draw_border
    side, border_edge, padding_edge)
  File "/usr/local/lib/python2.7/dist-packages/weasyprint/draw.py", line 477, in draw_border_segment
    dash = length / (2 * round(length / (2 * dash)))
ZeroDivisionError: float division by zero

Hyphenation: handle eg. fr_FR vs. fr

WeasyPrint only enables hyphenation when the lang attribute matches exactly the dictionary name. It should be smarter when matching languages.

Support @font-face on Linux

Today on IRC:

SimonSapin: Hi behdad. Does Pango have APIs to load a specific font file? (This is to implement web fonts in WeasyPrint.)
behdad: SimonSapin: no.
behdad: SimonSapin: however, you can subclass the FcFontMap and do it yourself.
behdad: that's what Firefox does.
behdad: don't ask me about the details... I don't quite know that myself either.
SimonSapin: behdad: I’ll look into it, thanks
behdad: well. that's not correct. I know. you can subclass PangoCairoFcFontMap
behdad: and override the create_font(), and figure it out from there
behdad: humm. something like that. don't remember the details.
behdad: the thing is, you need to work around the fontconfig layer

Now we only need to figure out how subclassing works in gobject. And all of fontconfig.

Tests fail on Slackware 13.37

From the Flask mailing-list:

Le 23/07/2012 22:37, Audrius Kažukauskas a écrit :

Installed Flask-WeasyPrint on Slackware 13.37 (full install) inside LXC
container with only virtualenv as additional package. Example app is
working fine.

Tried running WeasyPrint tests using the following command:

$ WEASYPRINT_USE_PYGTK=1 py.test

Three tests in tests/test_api.py are failing with the same exception:

TypeError: Surface.write_to_png takes one argument which must be a
filename (str), file object, or a file-like object which has a "write"
method (like StringIO)

Python version is 2.6.6, PyGObject 2.26.0, PyGTK 2.22.0, PyCairo 1.8.10.
If you need more details, let me know.

@audriusk, I’m taking this here to avoid spamming the list.

When you say only virtualenv, I assume you mean in addition to the dependencies as listed on the website? Does the test suite not run without WEASYPRINT_USE_PYGTK? The fall-back should be automatic if PyGObject is not installed. Could you run py.test --tb=native and copy the full tracebacks?

Thanks!

Encoding issue.

python 2.7
I have weasyprint library stored inside the project. Path to the project has russian letters.

Traceback (most recent call last):
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\main.py", line 6, in <module>
    from weasyprint import HTML
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\weasyprint\__init__.py", line 304, in <module>
    from .css import PARSER, preprocess_stylesheet
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\weasyprint\css\__init__.py", line 30, in <module>
    from . import computed_values
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\weasyprint\css\computed_values.py", line 20, in <module>
    from .. import text
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\weasyprint\text.py", line 18, in <module>
    import pyphen
  File "D:\\_IDE\eclipse\workspace\test\src - копия\src\pyphen\__init__.py", line 44, in <module>
    dictionaries_root = os.path.join(os.path.dirname(__file__), 'dictionaries')
  File "C:\dev\Python27\lib\ntpath.py", line 108, in join
    path += "\\" + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xea in position 70: ordinal not in range(128)

Should be something like:

encoding = sys.getfilesystemencoding()
__file__.decode(encoding)

svg not rendered correctly

I created an example svg file in inkscape (a circle and a square both inside a square).
I include it in the html like so :
<embed src="drawing-test.svg" type="image/svg+xml" ></embed>
In the browser it renders correctly. But the generated pdf doesn't print correctly.
The circle has shifted upwards somehow.
As I cannnot seem to attach the svg file so below the screendump:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="189.59375"
   height="94.5625"
   id="svg5078"
   version="1.1"
   inkscape:version="0.48.2 r9819"
   sodipodi:docname="drawing-test.svg">
  <defs
     id="defs5080" />
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="1.4"
     inkscape:cx="18.682745"
     inkscape:cy="-43.004391"
     inkscape:document-units="px"
     inkscape:current-layer="layer1"
     showgrid="false"
     inkscape:window-width="972"
     inkscape:window-height="786"
     inkscape:window-x="200"
     inkscape:window-y="90"
     inkscape:window-maximized="0"
     fit-margin-top="0"
     fit-margin-left="0"
     fit-margin-right="0"
     fit-margin-bottom="0" />
  <metadata
     id="metadata5083">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="Layer 1"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(-174,-139.50974)">
    <rect
       style="fill:none;stroke:#c0be7c;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
       id="rect5094"
       width="188.57143"
       height="93.571426"
       x="-7.1428571"
       y="-8.9963427"
       transform="translate(181.65625,149.00974)"
       ry="0" />
    <g
       id="g5090">
      <rect
         ry="5.8375711"
         y="150.13589"
         x="181.93977"
         height="66.715096"
         width="74.213242"
         id="rect5086"
         style="fill:#4100ff;fill-opacity:1;stroke:#c0be7c;stroke-width:0.59382242;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
      <path
         transform="matrix(0.60406126,0,0,0.58375711,34.80771,58.691567)"
         d="m 484.28571,212.36218 c 0,31.55913 -25.58373,57.14286 -57.14286,57.14286 -31.55913,0 -57.14285,-25.58373 -57.14285,-57.14286 0,-31.55913 25.58372,-57.14285 57.14285,-57.14285 31.55913,0 57.14286,25.58372 57.14286,57.14285 z"
         sodipodi:ry="57.142857"
         sodipodi:rx="57.142857"
         sodipodi:cy="212.36218"
         sodipodi:cx="427.14285"
         id="path5088"
         style="fill:#4100ff;fill-opacity:1;stroke:#c0be7c;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
         sodipodi:type="arc" />
    </g>
  </g>
</svg>

Trailing spaces affect right alignment

If right-aligned text ends with a space in the HTML source then that space incorrectly appears in the output.

For example see: http://www.stripey.com/demo/weasyprint/right_align.html

In Firefox all the right-justified ‘M’s line up nicely. In WeasyPrint the trailing spaces mess up the alignment. This output was generated by WeasyPrint 0.16: http://www.stripey.com/demo/weasyprint/right_align.pdf

Note that initial spaces correctly don't affect left-aligned text, as can be seen by the first paragraph in the example.

This sensitivity to trailing spaces means that omitting optional closing tags can change the appearance of a document; see the <td> without a </td> in the above demo. Removing the </p> at the very end of the file also changes the appearance, because the LF at the end of the final line then becomes part of the paragraph's contents.

Doesn't render embedded JPEG

I am trying to generate a PDF from an HTML document with embedded JPEGs on the page. The area where the image should be is just blank. Rendering PNG images works fine.

I get the error message (I've replaced the image URL in this example):

Error for image at http://example.com/myimage.jpg : SystemError('NULL object passed to Py_BuildValue',)

I am running on CentOS 6.3 x86_64 with Python 2.6.6 and installed WeasyPrint with the PyGTK2 package (2.16.0) and libxml2-devel (2.7.6) and libxslt-devel (1.1.26).

Any help is appreciated - I can give you a copy of the JPEG image and a barebones HTML example if you need it.

Thanks!

[feature] Ubuntu .deb-package creation patch

Ubuntu .deb-package creation patch.
For Your Project.

Usage

  • make deb - create deb. It placed in 'deb_dist' folder.

More

  • make test - run all tests
  • make check - check source code (via pylint)

Requies

  • python-stdeb - for create .deb from 'setup.py'
  • python-all - to build package

Patch

cat deb-package-creation.patch:

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..76d9a47
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+PYTHON=`which python`
+
+
+all: test deb
+
+deb:
+   $(PYTHON) setup.py --command-packages=stdeb.command bdist_deb
+
+test:
+   unit2 discover -t .
+   python -mpytest weasyprint
+
+check:
+   find . -name \*.py | grep -v "^test_" | xargs pylint --errors-only --reports=n
+   # pep8
+   # pyntch
+   # pyflakes
+   # pychecker
+   # pymetrics
+
+clean:
+   $(PYTHON) setup.py clean
+   rm -rf build/ MANIFEST dist build deb_dist
+   find . -name '*.pyc' -delete
+

GLib-GObject-CRITICAL **: gtype.c:2720: You forgot to call g_type_init()

I installed WeasyPrint and all packages that were listed in the Weasyprint - documentation

I'm using Mac OS X 10.8.2
and Python 2.7
And installed Weasyprint in my virtualenv .

Now when i try :
HTML('http://weasyprint.org/').write_pdf('/tmp/weasyprint-website.pdf')

I get following message in my console :

pydev debugger: starting
Ignored border-radius: 6px at 12:3, unknown property.
Ignored background: linear-gradient(#000, #111) at 59:3, invalid value.
Ignored box-shadow: 0 0 1em #888 at 65:3, unknown property.
Ignored text-shadow: 0 0 0.5em #444 at 77:3, unknown property.
Ignored transition: color 0.25s at 150:3, unknown property.
Ignored box-shadow: 0px 0px 2px #ddd at 167:3, unknown property.
Ignored border-radius: 0.2em at 168:3, unknown property.
Ignored text-shadow: 1px 1px 1px #111 at 171:3, unknown property.
Ignored transition: background 0.7s ease at 251:3, unknown property.
Ignored border-radius: 0.2em at 279:3, unknown property.
Ignored box-shadow: 0 0 2px #b7b7b7 at 280:3, unknown property.
Ignored background: url(img/content_haut.png) no-repeat top left, url(img/bas.png) no-repeat bottom right at 301:3, invalid value.
Ignored border-radius: 0.2em at 305:3, unknown property.
Ignored transition: background-color 0.3s linear at 368:3, unknown property.
Ignored box-shadow: 0 0 5px #D60 at 373:3, unknown property.
Parse error at 7:1, unknown at-rule in stylesheet context: @font-face
Parse error at 12:1, unknown at-rule in stylesheet context: @font-face
Parse error at 17:1, unknown at-rule in stylesheet context: @font-face
Parse error at 22:1, unknown at-rule in stylesheet context: @font-face
Parse error at 26:1, unknown at-rule in stylesheet context: @font-face
Parse error at 31:1, unknown at-rule in stylesheet context: @font-face

(process:49474): GLib-GObject-CRITICAL **: gtype.c:2720: You forgot to call g_type_init()

(process:49474): GLib-CRITICAL **: void g_once_init_leave(volatile void *, gsize): assertion `result != 0' failed

(process:49474): GLib-GObject-CRITICAL **: gtype.c:2720: You forgot to call g_type_init()

(process:49474): GLib-CRITICAL **: void g_once_init_leave(volatile void *, gsize): assertion `result != 0' failed

(process:49474): GLib-GObject-CRITICAL **: gtype.c:2720: You forgot to call g_type_init()

(process:49474): GLib-GObject-CRITICAL **: gtype.c:2720: You forgot to call g_type_init()

I googled the GLib-GObject-CRITICAL but didn't find a solution, does anyone knows how to fix this?

Embedding PDF causes error

$ weasyprint embedded_pdf_test_001.html embedded_pdf_test_001.pdf

(process:84202): GdkPixbuf-CRITICAL **: gdk_pixbuf_loader_close: assertion `error == NULL || *error == NULL' failed
Error for image at file:///[path_to]/xetex_test_005-crop.pdf : RuntimeError("cannot use string() on <cdata 'char *' NULL>",)

For convenience, I have uploaded:

xetex_test_005-crop.pdf was generated from xetex_test_005.tex by running:

$ xelatex xetex_test_005.tex; pdfcrop xetex_test_005.pdf

on OS X 10.6.8. The various packages were installed from MacPorts, except where indicated in the WeasyPrint installation instructions; the --system-site-packages option to virtualenv was used before using pip to install WeasyPrint.

Floats inside inlines are broken

Some cases are totally broken:

<style>
@page { margin: 0 }
body { margin: 0 }
p { padding: 0 5em }
p:last-child, p:first-child { text-align: justify }
span { background-color: rgba(255, 0, 0, 0.2); float: left; margin-left: -5em }
span + span { background-color: rgba(0, 0, 255, 0.2) }
i { background-color: rgba(0, 255, 0, 0.2); float: right; margin-right: -5em }
</style>

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p><span>ShorterButVeryLong</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>Shorter</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p><span>Shorter</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>Shorter</span> Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short <span>ribs</span> brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>Shorter</span> Pig sirloin tenderloin salami tongue short <span>ribs</span> chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short <span>ribs</span> chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Start <strong>before<span>Test</span> middle <span>Shorter</span>after</strong>
Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Start <strong>before<span>Test</span> middle <span>ShorterButVeryLong</span>after</strong>
Pig sirloin tenderloin salami tongue short ribs chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short <i>Ribs</i> chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short <i>BigBigBigRibs</i> chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,

<p>Test <span>VeryVeryVeryLong</span> Pig sirloin tenderloin salami tongue short <i>BigBigBigRibs</i> chicken
pork ground round ham hock kielbasa tail hamburger spare ribs. Rump sirloin
short ribs brisket jerky. Jowl pork chop ball tip spare ribs pancetta ham hock,
  • Justified, long float left.
  • Long float left.
  • Leading long float left.
  • Short float left.
  • Leading short float left.
  • Two short floats left on two different lines.
  • Two short floats left on the same line.
  • Long and short floats left in the same line.
  • Two short floats left, one in a nested tag.
  • Long and short floats left, on in a nested tag.
  • Long float left and short float right on the same line.
  • Long float left and long float right on the same line.
  • Justified, long float left and long float right on the same line.

Document disabling hyphenation

How to enable hyphenation is documented (by dd2f6cc), but not how to disable it within a region of a document that is otherwise hyphenated.

The value none appears to work, but I'm not sure if that's correct (or whether anything that isn't auto would happen to work, or something else).

To avoid hyphenating URLs and email addresses (which all of our links are) I'm doing this:

html { -weasy-hyphens: auto }
a    { -weasy-hyphens: none }

Links do not render in PDF.

from weasyprint import HTML
HTML(string='<a href="http://google.com">link</a>').write_pdf('tmp.pdf')

Makes non-clickable links in PDF

Resulting PDF only has one page

I just installed weasyprint on Ubuntu. It seems to work great but the resulting PDF only has one page.

I'm trying to generate a PDF from a Sphinxdoc. WeasyPrint is smart enough to strip away the left hand navigation and only render the real content of the docs but it just stops after the first page. At the very bottom o f the page I can see half of a line of text and then the document just ends.

This seems to a problem specific to Sphinxdocs. I just tried to render the weasyprint website and this works, I get multiple pages. Then I tried to render some sphinxdocs (i.e. weasyprint http://bitmazk-pte-ltd.readthedocs.org/en/latest/code_conventions/python.html test.pdf) and again I end up with just one page.

Do I need to add the -s flag and add some css tricks in order to get proper page breaks?

Floating outside the parent box makes surrounding text leak

Applying a margin to a floated element can make text that flows round it leak outside its box,if the floated element fits entirely outside the box. See http://www.stripey.com/demo/weasyprint/float_outside_box.html and http://www.stripey.com/demo/weasyprint/float_outside_box.pdf

Each is floated left and has a negative left margin, so it starts left of its parent <p>. In the first paragraph the text of the <span> extends far enough back into the <p>, and the rest of the <p> text flows round it, as expected.

In the second paragraph the <span> text is short enough to fit entirely outside the content area of the <p>; the rest of the text in the <p> can avoid it simply by staying inside the <p>. This is what happens in Firefox and Chrome. But in Weasyprint the first line of the following text starts immediately after the right edge of the <span>, left of its own content area; it's moved into the negative margin that should only apply to the <span>.

Enable PDF embedding

For background, see #51

With latest version of cairocffi, attempting to embed PDF produces the following Terminal output under OS X 10.6.8:

$ weasyprint embedded_pdf_test_001.html embedded_pdf_test_001.pdf
Error for image at file:///[path_to]/xetex_test_005-crop.pdf : ValueError(u'Pixbuf error: Unrecognised image file format',)

The resulting output PDF contains the other parts of the input HTML content, but does not contain the embedded PDF.

Value for right: ignored on <img>

Have a look at http://www.stripey.com/demo/weasyprint/abs_pos.html and its output in WeasyPrint: http://www.stripey.com/demo/weasyprint/abs_pos.pdf

The red squares are <span>s; the yellow ones <img>s.

The top pair have right: 5ex, which positions the <span> correctly, but on the <img> is being treated as right: 0.

The bottom pair show the workaround: using right: 0; margin-right: 5ex, which works on both the <span> and the <img>.

All 4 boxes are positioned as I'd expect in Firefox and Chromium.

Embed jpeg images in pdf

Currently jpeg images are converted into png. Cairo supports embeding jpegs via cairo_surface_set_mime_data.

However this function doesn't seem to have been exposed via pycairo yet. It would be great if this were implemented, currently my pdf files are ca. 10x the size they need to be.

Feature Request: Support CSS3 Text (word-wrap, word-break).

Specifically, word-wrap and word-break. Relevant spec: http://dev.w3.org/csswg/css3-text/#overflow-wrap

HTML:

<table>
    <tr>
        <td class="wrappable" style="width: 100px">
            ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
        </td>
    </tr>
</table>

CSS:

.wrappable {
    word-wrap: break-word;
    word-break: break-all;
    overflow: hidden;
}

Example: http://fiddle.jshell.net/qBj4R/show/

Page margins are broken with "body { overflow: auto }" style

I have a CSS file that defines headers and footers using @top-center, @bottom-center, and @top-right. When I use weasyprint the resulting PDF does not have the headers and footers. Here's a snippet from the CSS file:

@page
{
    size: letter;
    margin: 27mm 16mm 27mm 16mm;
    counter-increment: page;
    @bottom-center
    {
        content: counter(page);
        white-space: pre;
        color: grey;
        }
    @top-center
    {
        content: 'Strategic Planning Concept';
        color: grey;
        border-bottom: solid 1px grey;
    }
    @top-left
    {
        content: ' \a \a \a ';
        white-space: pre;
        color: grey;
        border-bottom: solid 1px grey;
    }
    @top-right
    {
        content: ' \a \a \a February 6, 2013';
        white-space: pre;
        color: grey;
        border-bottom: solid 1px grey;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.