Git Product home page Git Product logo

prawn's People

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

prawn's Issues

please include min_version patch

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.

Ghostscript and ImageMagick need \n after %%EOF

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.

Vertical align for cells

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.

center layout incorrect

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

Prawn PNG Issues

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

Prawn::Format issue on tag

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.

move_cursor_to

having to do pdf.y = dy + bounds.absolute_bottom sucks.

require "enumerator" in graphics.rb should be removed

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!

NameTree insertion bug

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

Transparency and stamp changes made

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

compute_width_of() seems to consider unicode as single byte character-set

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')

Embed other PDF images

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.

Tweak Document#text_box to implement some features from PDF::Writer#add_text_wrap

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.

When Prawn#text_box is called with the :angle => (int in range 0..259) option, the text is rotated as it would be using PDF::Writer #add_text_wrap 3. When Prawn#text_box is called with the :justification => :left | :center option, the text is justified as it would be using PDF::Writer #add_text_wrap

:column_color

A clone of :row_color but for the columns of a table.

column_box doesn't flow between columns when displaying tables instead of text

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

Add DeviceN colorspace support

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.

text method :at and :align options

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.

Table breaks with non-standard leading (:spacing)

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.

unfilter_image_data is a dog

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.

PDF Meta Data

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.)

rounded_rectangle

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.

Document#grouped

A bit pie in the sky at the moment, but....

grouped do
   # ...
end

Would attempt to keep contents on the same page

Binary sentinel in header needs to be in PDF comment

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.

Make bounding_box fully enclose nested elements

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å

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.