prawnpdf / prawn-templates Goto Github PK
View Code? Open in Web Editor NEWExperimental extraction of template features from Prawn
License: Other
Experimental extraction of template features from Prawn
License: Other
This is a prawnpdf/prawn#293. I ran into this issue and figured out the cause and a workaround that I'm using via monkey patching. I'm posting my analysis of the bug here since apparently there's an attempt to revive the templates code.
The problem lives in PDF::Core::Page. Basically when templates are used, the size instance variable does not get set, so calls to page.size just return the dimensions. However, when this value is fed back into Page.new to create a new page, it reverses the coordinates if the layout is landscape. Since page.size already gives you the coordinates in landscape, reversing them makes it portrait. The below change to the method ensures that the size method always returns coordinates as if the layout was portrait
module PDF
module Core
class Page
def size
return @size if defined?(@size) && @size
case(layout)
when :portrait
dimensions[2,2]
when :landscape
dimensions[2,2].reverse
end
end
end
end
end
This would be tricky to fix for real since it's in pdf core, but it might represent a legitimate bug there too.
@pointlessone Is this repo still maintained as part of the prawnpdf set? Should I get it working with GitHub Actions, prawn-dev, etc?
There are ways in Ruby to override a method without generating a warning. Please consider using one of those approaches to override the methods in PDF::Core. This will avoid the following warnings:
../gems/prawn-templates-0.0.5/lib/pdf/core/document_state.rb:4: warning: method redefined; discarding old initialize
../gems/pdf-core-0.7.0/lib/pdf/core/document_state.rb:4: warning: previous definition of initialize was here
../gems/prawn-templates-0.0.5/lib/pdf/core/object_store.rb:4: warning: method redefined; discarding old initialize
../gems/pdf-core-0.7.0/lib/pdf/core/object_store.rb:16: warning: previous definition of initialize was here
../gems/prawn-templates-0.0.5/lib/pdf/core/page.rb:4: warning: method redefined; discarding old initialize
../gems/pdf-core-0.7.0/lib/pdf/core/page.rb:24: warning: previous definition of initialize was here
../gems/prawn-templates-0.0.5/lib/pdf/core/page.rb:43: warning: method redefined; discarding old dimensions
../gems/pdf-core-0.7.0/lib/pdf/core/page.rb:150: warning: previous definition of dimensions was here
Here are some strategies:
alias :__initialize :initialize
)
I need to render an image behind the content from the template. Is that possible?
it looks like permission to push to rubygems has been granted, but the published version is still at 0.3
It would be nice to have 0.5 on rubygems!
I've collected the following links that demonstrate the problem:
There's also a very comprehensive StackOverflow answer that might explain what's going on.
See also:
This is a critical issue for my app, so I will attempt to fix it myself. I'll submit a PR if I manage to solve the problem. Any assistance would be greatly appreciated!
This change to prawn will result in:
RuntimeError: can't modify frozen array
<< at org/jruby/RubyArray.java:1240
<main> at /home/tyler/source/github/jenkins-infra/jenkins.io/build/tmp/asciidoctor/gems/prawn-templates-0.0.3/lib/prawn/templates.rb:246
require at org/jruby/RubyKernel.java:961
require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55
<main> at /home/tyler/source/github/jenkins-infra/jenkins.io/build/tmp/asciidoctor/gems/asciidoctor-pdf-1.5.0.alpha.14/lib/asciidoctor-pdf/converter.rb:1
require at org/jruby/RubyKernel.java:961
(root) at /home/tyler/source/github/jenkins-infra/jenkins.io/build/tmp/asciidoctor/gems/asciidoctor-pdf-1.5.0.alpha.14/lib/asciidoctor-pdf/converter.rb:10
<main> at uri:classloader:/jruby/kernel/kernel.rb:1
require at org/jruby/RubyKernel.java:961
require at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:55
<main> at uri:classloader:/jruby/kernel/kernel.rb:13
load at org/jruby/RubyKernel.java:979
<main> at /home/tyler/source/github/jenkins-infra/jenkins.io/build/tmp/asciidoctor/bin/asciidoctor-pdf:22
Since prawn-template tries to append to the, now frozen, Prawn::Document::VALID_OPTIONS
array.
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.