Comments (13)
I was just about to post on this problem.
A more-inclusive take on the GSUB is:
.gsub(/(src|href)="//) { |s| "#{$1}="http://#{request.host_with_port}/" }
This covers javascript, images, stylesheets and probably a few others without having app-specific selectors in there.
from wicked_pdf.
That could definitely work, but as I mentioned above, I ran into a problem where javascript was causing wkhtmltopdf to hang. I'm not sure if it was a problem with ruby 1.8.5 or the version of wkhtmltopdf I was using, but removing javascript fixed it. I tested on a Mac system running 1.8.7 and did not experience the same issue. Just a heads up for anyone who might also experience that.
from wicked_pdf.
There's a flag on the wkhtmltopdf command that prevents JS/plugins from running, plus a few other useful flags such as rendering in 'print' media mode.
from wicked_pdf.
Just to point out a small fix to dougal's code,
.gsub(/(src|href)="//) { |s| "#{$1}="http://#{request.host_with_port}/" }
from wicked_pdf.
This helper works perfectly for making correct image tags:
def pdf_image_tag(image, options = {})
options[:src] = File.expand_path(RAILS_ROOT) + '/public/images/' + image
tag(:img, options)
end
from wicked_pdf.
Another small fix to handle SSL and single quotes:
html.gsub(/(src|href)=('|")//) { |s| "#{$1}=#{$2}#{request.protocol}#{request.host_with_port}/" }
from wicked_pdf.
Hi, I'm relatively new to RoR and currently trying to render images inside the pdf (using wickedpdf). I added the method , suggested by gipnokote for "pdf_image_tag" but I'm not really sure how to access it now.
Any help or point in the right direction is appreciated.
from wicked_pdf.
mgharios,
I use it in the view simply like this (image should be stored in the public/images/ folder):
<%= pdf_image_tag 'logo.png' %>
You can also add any HTML options after the image name like this:
<%= pdf_image_tag 'logo.png', :alt => 'This is the logo' %>
from wicked_pdf.
gpnokote, thanks for the quick reply! I tried this and it tells me the method is not defined "undefined method `pdf_image_tag' for #ActionView::Base:0x477aef0".
My pdf_helper.rb is located under Vendor/plugins/wicked_pdf_lib. The html view i'm calling it from belongs to an object "customers". Should I move pdf_helper.rb file or include it somewhere ?
thanks!
from wicked_pdf.
mgharios, I don't think you shoult put anything under vendor/plugin folder in this case.
You have several options now. If you generate pdf in Orders controller for example, you can put this function definition into either:
- app/helpers/order_helper.rb (your current controller helper)
- app/helpers/application_helper.rb (things in this helper are always visible in all views)
- app/helpers/pdf_helper.rb (custom helper, in this case you have to include it in your controller like this):
helper :pdf_helper
from wicked_pdf.
This is GREAT! Thank you! I didn't realize I can put this method in any helper ( for some reason I thought it had to be inside the pdf_helper.rb which is part of the wickedpdf. Anyway, I ended using method # (1) from your options and put it into customers_helpe.rb which is where I'm generating my pdf from :)
thanks again!
Marina
from wicked_pdf.
The
wicked_pdf_stylesheet_link_tag("pdf") (in wicked_pdf_helper.rb)
does not work correctly on windows
instead :
i get :
<link href="/stylesheets/pdf.css?1293633573" media="all" rel="stylesheet" type="text/css" />
<link href="/stylesheets/C:/Users/foton/Documents/workspace/app1/public/stylesheets/pdf.css" media="all" rel="stylesheet" type="text/css" />
Prefix "/stylesheets/" for fullpath css is wrong.
Any better way to construct correct stylesheet link?
Foton
from wicked_pdf.
This helper code works for me.
def absolute_path_for_src(body)
body.gsub(/(src|href)=('|")\//) { |s| "#{$1}=#{$2}#{request.protocol}#{request.host_with_port}/" }
end
from wicked_pdf.
Related Issues (20)
- Add support for --load-error-handling and --load-media-error-handling
- Remote asset returning non-200 response does not trigger an error
- Greek Character "𝛼" not showing correctly within PDF generated by Wicked PDF HOT 7
- Images won't load from Active Storage using Amazon S3 Bucket HOT 2
- version 2.7.0 breaks with webpacker
- Content is getting cropped in PDF
- ActionView::Template::Error uninitialized constant WickedPdf::WickedPdfHelper::Assets::SprocketsEnvironment::Sprockets HOT 3
- Feature Request: PDF/A-1
- pdf_from_url CSS not working HOT 1
- Raw PDF being rendered. HOT 1
- OpenStruct causes NameError in Rake13.2.0
- PDF is being rendered with raw ERB code HOT 4
- Content overlaps with the header layout
- RuntimeError on PDf Generation HOT 1
- wicked_pdf due to wkhtmltopdf not finding OpenSSL 1.1 despite installing over OpenSSL 3 HOT 7
- Remove usage of `OpenStruct` or add `ostruct` as dependency
- v2.8.0 causing ActionView::Template::Error: no implicit conversion of nil into String for first time in years HOT 7
- ArgumentError when changing the WickedPdf.config={...} to the new WickedPdf.configure.do |c| ... end HOT 1
- Error: PDF could not be generated! HOT 1
- Public assets not getting loaded after upgrade to Rails 7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wicked_pdf.