prawnpdf / prawn Goto Github PK
View Code? Open in Web Editor NEWFast, Nimble PDF Writer for Ruby
Home Page: https://prawnpdf.org
License: Other
Fast, Nimble PDF Writer for Ruby
Home Page: https://prawnpdf.org
License: Other
Font#normalize_encoding is described in the docs as modifiying the argument, which it does not anymore. Font#normalize_encoding! is the destructive version of the method.
While trying to work with column_box I found out that plain text works well but tables don't flow properly.
This works fine:
column_box [0,cursor], :width => bounds.width, :columns => 2 do
text " This is a test " * 100
end
This just causes the tables to continue in the first column over multiple pages, never flowing into the second column:
column_box [0,cursor], :width => bounds.width, :columns => 2 do
table data, :headers => headers,
:header_color => 'C0C0C0',
:font_size => 7,
:border_style => :grid,
:border_width => 0.5,
:width => bounds.width-10
end
Hi
I am creating a request here according to the discussions at
http://groups.google.com/group/prawn-ruby/browse_thread/thread/aef186542b250187
Could anybody give a solution to this?
Thanks
sk
POLS?
Add option to position an image on the page, but not move the text cursor afterwards. See shammond42/prawn (http://github.com/shammond42/prawn/tree/) for implementation, documentation and examples.
Having both :at and :align options on the text method, makes you think they would work together, which they don't. This should be fixed, or reflected in the documentation.
Need to add documentation for cases where non-standard page size is required (ie not included in Document::PageGeometry::SIZES):
Use [width, height] instead of a symbol. (In PDF points 1/72 in)
This is a prerequisite for a project aimed at creating a duotone tool in ruby. Necessary for all documents using spot colors. BTW I guess there is no reason why Prawn should not support all the remaining colorspaces that PDF offers.
Greg, Brad, I've incorporated the changes you recommended and made a few other improvements (such as a couple new specs). Please note that everything for both transparency and stamp is now on the master of my Prawn fork: http://github.com/bluejade/prawn. I hope that works okay for you.
Please let me know if anything else should be done on these.
Best,
Daniel
As someone else mentioned on the list, support for configuring letter spacing would be nice.
Including a PNG with RGB+alpha (color type 6) in a PDF is not feasible because the method "unfilter_image_data" is incredibly slow. A quick benchmark of spec/png_spec.rb with and without the tests that hit this method:
(2.4GHz Intel Core 2 Duo)
with: "Finished in 13.779863 seconds."
w/out: "Finished in 0.391898 seconds."
That's on a 320x240 pixel PNG. It gets a lot worse the bigger they get. I have a use case where a 474x719 PNG is included in a PDF and it takes 24 seconds to create.
The bummer here is that many graphical apps (Pixelmator, Illustrator, etc) always flip the alpha transparency bit so this affects many images.
Would it be possible (or even a good idea) to change document.width_of so that it always does a normalize_encoding automagically?
using center layout in prawn is not correct as the length of lines is not correctly determined (incloding '\n' character)
This was published and discussed on in google group:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/6754ada443dd22cd
workaround is to overwrite width_of method by manually removing tailing '\n' characters. (sorry the layout is broken as githup is always reformating this as coding)
module Prawn
class Document
alias_method :orig_width_of, :width_of
def width_of(string, options={})
orig_width_of(string.gsub(/\n\z/,""),options)
end
end
end
Hi,
I got an error
/usr/lib64/ruby/gems/1.8/gems/prawn-format-0.2.0.1/lib/prawn/
format/parser.rb:120:in `start_parse': closing b, but no tags are open
(Prawn::Format::Parser::TagError)
when displaying text like that
pdf.text "this is simple plain text where plain = true
", :plain => true
This is working fine in earlier version.
(Note: I've replaced this ticket with a different description --greg)
See http://github.com/rogergl/prawn/commit/5f11d7701e9b63c62d6b7ad3922a3029740f2344 for a reference implementation, but we really should centralize our alignment hackery so we don't repeat this same basic procedure again and again
rename prawn-core/lib/prawn.rb to prawn-core/lib/prawn/core.rb and have the Prawn gem require it.
This fixes weird rubygems issues.
Trying to keep my images in a vector format so that printing and scaling of the prawn generated document stays crisp and lightweight. Would love to be able to embed either EPS or PDF vector art into my prawn generated document.
See title :)
I had used prawn to generate some chinese pdf documents successfully
when set the :wrap option to :character, but the wrap function failed for document which include tags
after I required 'prawn/format'.
The min_version() method in my fork will be useful for extensions that use features that require PDF versions > 1.3
Most readers seem to ignore the version anyway, but we probably should at least try to be good PDF citizens.
I have looked through the PDF-reference and can't find a way to do rectangles with rounded corners at the PDF-level, so it seems this should be done like PDF-writer did it, by drawing lines and curves.
A working method was submitted by Benjamín Cárdenas Salamandra in this thread:
http://groups.google.com/group/prawn-ruby/browse_thread/thread/9505ce1a5fade296
Here it is again:
def rectangle_rounded(point,width,height,radius)
x,y = point
line [x+radius,y],[x+width-radius,y]
line [x+radius,y-height],[x+width-radius,y-height]
line [x,y-radius],[x,y-height+radius]
line [x+width,y-radius],[x+width,y-height+radius]
l1 = radius * KAPPA
y1 = y-radius+l1
x1 = x+radius-l1
x2 = x+width-radius+l1
y2 = y-height+radius-l1
curve [x,y-radius],[x+radius,y], :bounds => [[x,y1],[x1,y]]
curve [x+width-radius,y],[x+width,y-radius], :bounds => [[x2,y],[x+width,y1]]
curve [x+width,y-height+radius],[x+width-radius,y-height], :bounds => [[x+width,y2],[x2,y-height]]
curve [x+radius,y-height],[x,y-height+radius], :bounds => [[x1,y-height],[x,y2]]
end
UPDATE: This method works well for stroked rounded rectangles, but not if you fill it. I'm working on an implementation that works for both cases, but haven't finished it yet.
ImageMagick (and reportedly Ghostscript) doesn't like Prawn's EOF syntax. I don't believe the particular file in question is relevant -- any PDF from Prawn spits out this error:
$ convert --version
Version: ImageMagick 6.5.1-0 2009-05-23 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
$ convert -quality 100 out/0000.pdf out/0000.jpg
**** This file has a corrupted %%EOF marker, or garbage after the %%EOF.
**** The file was produced by Prawn:
**** please notify the author of this software
**** that the file does not conform to Adobe's published PDF
**** specification. Processing of the file will continue normally.
Of course, this is a lie; the file is in compliance with the Adobe spec, but ImageMagick expected a newline after the %%EOF marker. Adding the newline silences that warning. According to the PDF spec (reference 1.3, appendix H, implementation note 15), Adobe readers accept %%EOF anywhere in the last 1024 bytes of the file.
Patched at bradediger/prawn@f8f5257. Hopefully patches are accepted to make my life easier on busted unsupported viewers.
This is a request for several enhancements to Prawn#text_box so that it would support the features of #add_text_wrap in PDF::Writer.
1. When Prawn#textbox is called with the :truncate or :ellipses option the text which is not displayed in the text box is returned. (Implemented by geeksam and merged for 0.6)_
2.
In PDF::Writer I could set the document properties “author”, “title”, “keywords”, “subject”, “creator”, “producer”.
(It’s been my experience that these help with SEO.)
A clone of :row_color but for the columns of a table.
In ruby 1.8.7, enumerator.rb doesn't exist. It's not a problem if a script using prawn is executed by ruby interpreter, however, a Windows binary generated by exerb from the script cannot execute correctly because the binary tries to load enumerator.so but cannot load it.
Please fix this issue. Thanks!
Hello
As I already reported in a ticket on prawn.lighthouseapp.com/ (URL: http://is.gd/1bGe3 ) for 0.4 in 0.5.1 remains a bug with table cells and a :leading greater than 0. In particular the bug is in prawn/document/text/wrapping.rb and does probably not only concern tables.
A sample script that produces the misbehavior is here: https://prawn.lighthouseapp.com/attachments/128185/prawntest.rb
I fixed it for me in the following way (diff for wrapping.rb):
22c22,23
< string.lines.to_a.length * font.height_at(size)
---
> lcount = string.lines.to_a.length
> lcount * font.height_at(size) + ( lcount - 1 ) * text_options[:spacing].to_f
So long, T.
I just found what i think is a bug in the nametree << method :
That code taken from name_tree_spec.rb works ok:
it "should keep tree balanced when subtree split cascades to root" do node = Prawn::NameTree::Node.new(@pdf, 3) tree_add(node, ["one", 1], ["two", 2], ["three", 3], ["four", 4]) tree_add(node, ["five", 5], ["six", 6], ["seven", 7], ["eight", 8]) tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]" end
but the same code with the values pre-ordered doesn't :
it "should keep tree balanced when subtree split cascades to root" do node = Prawn::NameTree::Node.new(@pdf, 3) tree_add(node, ["eight", 8], ["five", 5], ["four", 4,], ["one",1] tree_add(node, ['seven', 7], ['six', 6], ['three', 3], ['two', 2]) tree_dump(node).should == "[[[eight=8,five=5],[four=4,one=1]],[[seven=7,six=6],[three=3,two=2]]]" end
Here is the output :
/usr/lib/ruby/gems/1.9.1/gems/prawn-core-0.5.1/lib/prawn/name_tree.rb:83:in `<<': undefined method `<<' for nil:NilClass (NoMethodError) from /usr/lib/ruby/gems/1.9.1/gems/prawn-core-0.5.1/lib/prawn/ name_tree.rb:42:in `add' from name_tree_spec.rb:13:in `block in tree_add' from name_tree_spec.rb:12:in `each' from name_tree_spec.rb:12:in `tree_add'
nametree.rb:83 is "fit << value"
but fit is nil because in the previous line : fit = children.detect { |
child| child >= value }
"child >= value" is always false if the values inserted are already
ordered.
This patch fixes it for me :
diff --git a/lib/prawn/name_tree.rb b/lib/prawn/name_tree.rb index 267a6e9..c7d20c8 100644 --- a/lib/prawn/name_tree.rb +++ b/lib/prawn/name_tree.rb @@ -79,6 +79,7 @@ module Prawn split! if children.length > limit else fit = children.detect { |child| child >= value } + fit = children.last unless fit fit << value end
jlh
Hello
For example for german umlauts compute_width_of() reports up to the double width of the same character without diaeresis (e.g. Ü has twice the width of U).
Here some sample code:
#!/usr/local/bin/ruby require 'rubygems' require 'prawn' pdf = Prawn::Document.new %w(wertbestätigung wertbestatigung Ä A Ü U Ö O Â A).each do |heading| str_width = pdf.font.compute_width_of(heading) pdf.text "#{heading} width: '#{str_width}' " end def print_stretched pdf, string, gap, position_y char_h = {} string_width = 0.0 offset = 0 char_a = string.split('') char_a.each { |c| string_width += char_h[c] = pdf.font.compute_width_of(c).to_f } string_width += ( char_a.length - 1 ) * gap position_x = pdf.bounds.width / 2 - string_width / 2 char_a.each do |c| pdf.text c, :at => [position_x+offset, position_y] offset += char_h[c] + gap end end pos = 400 %w(rechnung kostenvoranschlag wertbestätigung angebot).each do |heading| print_stretched pdf, heading, 2.0, pos pos+= 30 end pdf.render_file('stretched.pdf')
Currently, Prawn does not support displaying the total page count of the generated PDF. From this post I implemented the suggested hack in my forked version of prawn located here
Testing this new issues hotness
If a table cell is wide, the next table header wraps, or all subsequent table headers overlap into the final. This can occur in the middle of the table.
you wrote that i should create an issue to remind you. so please apply my fixes:
http://github.com/corny/prawn-layout/commit/7524535bd421e36594ae1b64c8160fca0cb4fb36
http://github.com/corny/prawn-layout/commit/3883f8b9c6ac3b0dff017c28b3e01b8715b31d7f
http://github.com/corny/prawn-layout/commit/8738c3d51cacbf57b2452e47323a5a9d27721270
Allow printer's marks (bleed, crop, etc) to be drawn on the pages through use of something like :prepress => [bleed, crop] in Document.generate.
Examples:
http://www.jukeboxprint.com/images/crop_marks.gif
http://www.ewbi.com/ewbi.develop/graphics/word.crop.marks.jpg
The four binary characters recommended by the spec (as a sentinel for file-transfer programs) should be in a PDF comment: "it is recommended that the header line be immediately followed by a
comment line containing at least four binary characters". Confirmed that at least Apple's PDF framework does this correctly.
Fixed in bradediger/prawn@a14f21e4. Sending pull request.
A bit pie in the sky at the moment, but....
grouped do
# ...
end
Would attempt to keep contents on the same page
Allow :margins => [a,b,c,d] or even :margins => k
It would be very convenient to a project I’m doing if it were possibly to do, e.g.
pdf.cell blahblah, :vertical_align => :center
and have that work as easily as :horizontal_align => :center does. You can “fake it” with vertical padding fairly easily… right until you end up word wrapping.
I’m currently banging my head against this for my project but if I get a generalizable solution working I’ll try getting you guys the code.
Improves consistency with typesetting vocabulary.
having to do pdf.y = dy + bounds.absolute_bottom sucks.
As per Greg’s request in the following mailing list post, here’s a feature request: http://groups.google.com/group/prawn-ruby/browse_thread/thread/229740129eb9a506
The behaviour of bounding_box should be changed to fully enclose nested elements, such that Prawn elements that follow a bounding box containing multiple nested elements with varying heights will align with the bottom edge of the bounding_box, and not the bottom edge of the last rendered nested element. This should obviously only be the case if the following element uses ‘cursor’ to denote it’s y-axis alignment.
I hope I’ve elucidated adequately.
Samå
https://prawn.lighthouseapp.com/attachments/61121/interlaced.png
Here’s a sample image Prawn chokes on. This is your dice.png. I just reopened it in Photoshop and resaved it with the interlaced setting on. Prawn now chokes on parsing it, reporting the wrong error mid-parse.
In addition, see the discussion at:
https://prawn.lighthouseapp.com/projects/9398-prawn/tickets/82-adding-a-png-to-a-pdf-appears-corrupted
It seems that font.width_of was changed to font.compute_width_of
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.