Html2Pdf CSS aware formatting language for Prawn!

130 views
Skip to first unread message

Kristian Mandrup

unread,
May 21, 2010, 9:29:14 PM5/21/10
to Prawn
I'm in the proces of creating a new Html2Pdf formatting language, that
is partly CSS aware.
Can also load css from external stylesheets using <link tags and
applies styles on elements according to w3c specificity!

The following works ;)

simple_html = %q{
<p style="font-size:20; color: red">
<span style="color: #0f0; font-size:10; font-weight:bold; font-
style: italic">Hello Kitty</span>
Katty
</p>}

doc = Prawn::Document.new(:page_size => "A4")
# PdfGenerator::Html.generate('kitty_adv.pdf') do
PdfGenerator::Html.document(doc) do
apply(simple_html)
end

Gregory Brown

unread,
May 22, 2010, 5:46:51 AM5/22/10
to prawn...@googlegroups.com
On 5/21/10 9:29 PM, Kristian Mandrup wrote:
> I'm in the proces of creating a new Html2Pdf formatting language, that
> is partly CSS aware.
> Can also load css from external stylesheets using <link tags and
> applies styles on elements according to w3c specificity!

Link to code?

Anuj Dutta

unread,
May 22, 2010, 6:25:03 AM5/22/10
to prawn...@googlegroups.com
Strange... I have also started working on something similar.

Anuj
@andhapp
------------------

Gregory Brown

unread,
May 22, 2010, 6:24:33 AM5/22/10
to prawn...@googlegroups.com
On 5/22/10 6:25 AM, Anuj Dutta wrote:
> Strange... I have also started working on something similar.

Do you have a link? ;)

-greg

Anuj Dutta

unread,
May 22, 2010, 6:35:45 AM5/22/10
to prawn...@googlegroups.com
It's in a very early stage at the moment but I will clean it up a bit and then share it here.

Anuj

------------------

-----Original Message-----
From: Gregory Brown <gregor...@letterboxes.org>
Date: Sat, 22 May 2010 06:24:33
To: <prawn...@googlegroups.com>
Subject: Re: Html2Pdf CSS aware formatting language for Prawn!

Kristian Mandrup

unread,
May 22, 2010, 2:36:10 PM5/22/10
to Prawn
http://github.com/kristianmandrup/html2pdf

Anuj, let's join forces!. We can check out each others code and see if
we can integrate the efforts and which code to use as the base.
My code is also at a very experimental stage, with focus on the CSS
part so far.
It just seems that prawn is just about ready for a html2pdf converter
with the latest additions since 0.9.
Cheers!

Kristian

Anuj Dutta

unread,
May 22, 2010, 2:47:34 PM5/22/10
to prawn...@googlegroups.com
Yeah. Ofcourse. I will have a look at your code tonight. It's better to work together. I will e-mail you the exact route I would like to take and where I am with it at the moment and we can then hopefully work out a plan.

Thanks for consideration.

Cheers.

Anuj


------------------

-----Original Message-----
From: Kristian Mandrup <kman...@gmail.com>
Date: Sat, 22 May 2010 11:36:10
To: Prawn<prawn...@googlegroups.com>
Subject: Re: Html2Pdf CSS aware formatting language for Prawn!

Kristian Mandrup

unread,
May 22, 2010, 3:58:59 PM5/22/10
to Prawn
Sounds great! I am pretty much newcomer to the latest Prawn
developments. Do you by any chance know how to calculate the width of
a text bounding box?

b = Prawn::Text::Formatted::Box.new([fragment],
options.merge(:document => pdf))
b.render(:dry_run => true)
b.height

But there doesn't seem to be a width method? There is however a width
method on a fragment, but ... and what about the bounding_box and
absolute_bounding_box ?
I guess each letter has a different width, but I would assume that as
the letters/symbols are rendered, their total width could be added up
and stored?

I want to be able to create a border around formatted text and also
allow for a background color.

Thanks!

Kristian

Anuj Dutta

unread,
May 22, 2010, 4:04:09 PM5/22/10
to prawn...@googlegroups.com
Well, I am a newcomer as well but I will have a look at this one and get back to you on this one.

Kristian Mandrup

unread,
May 22, 2010, 6:16:26 PM5/22/10
to Prawn
Thanks! I solved it already, except now I'm having problems with the
order of drawing operations.
I only solved it when externalizing it from Prawn, thereby gaining
"full control". But trying to refit it an integration in core Prawn
IMO... I hit the wall.
But it feels better if you could do true underlays in core Prawn,
thereby simulating multiple render layers.
See my post on underlays.
Reply all
Reply to author
Forward
0 new messages