Giter Site home page Giter Site logo

Comments (13)

dougal avatar dougal commented on August 27, 2024

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.

beerlington avatar beerlington commented on August 27, 2024

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.

dougal avatar dougal commented on August 27, 2024

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.

asteed avatar asteed commented on August 27, 2024

Just to point out a small fix to dougal's code,

.gsub(/(src|href)="//) { |s| "#{$1}="http://#{request.host_with_port}/" }

from wicked_pdf.

gipnokote avatar gipnokote commented on August 27, 2024

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.

skaczor avatar skaczor commented on August 27, 2024

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.

mgharios avatar mgharios commented on August 27, 2024

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.

gipnokote avatar gipnokote commented on August 27, 2024

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.

mgharios avatar mgharios commented on August 27, 2024

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.

gipnokote avatar gipnokote commented on August 27, 2024

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:

  1. app/helpers/order_helper.rb (your current controller helper)
  2. app/helpers/application_helper.rb (things in this helper are always visible in all views)
  3. 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.

mgharios avatar mgharios commented on August 27, 2024

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.

foton avatar foton commented on August 27, 2024

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.

suneelkumar91 avatar suneelkumar91 commented on August 27, 2024

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)

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.