Hello, I''m writing a mail-merge application with Ruby on Rails. I have one user-created template, wich he creates with a CKEditor (in HTML). I have a list of members, and in the "mailings" controller I mix the template with the members data to create a PDF with a letter to every member. This is all working correctly... Except one part: I don''t know how to render correctly the HTML in the PDF file. Currently I use the Prawn library to create the PDF''s. The generation of the PDF is very easy, but it doesn''t render the HTML codes, so if in the template appears something like "<b>Hello Mr. {NAME}</b>", in the final PDF appears the same text, and not "Hello Mr. {NAME}" in bold... How can I create PDF''s with Prawn from HTML formatted templates? If it isn''t possible, which PDF library can I use? I''m using Rails 3.2. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 22, 2012, at 11:00 AM, Marc C. wrote:> Hello, > > I''m writing a mail-merge application with Ruby on Rails. I have one > user-created template, wich he creates with a CKEditor (in HTML). I have > a list of members, and in the "mailings" controller I mix the template > with the members data to create a PDF with a letter to every member. > This is all working correctly... Except one part: I don''t know how to > render correctly the HTML in the PDF file. > > Currently I use the Prawn library to create the PDF''s. The generation of > the PDF is very easy, but it doesn''t render the HTML codes, so if in the > template appears something like "<b>Hello Mr. {NAME}</b>", in the final > PDF appears the same text, and not "Hello Mr. {NAME}" in bold... > > How can I create PDF''s with Prawn from HTML formatted templates? If it > isn''t possible, which PDF library can I use? I''m using Rails 3.2.I''ve used PrinceXML (not at all free) with great results in the past. It handles valid and invalid (X)HTML input and generates a very usable PDF as a result. They have a free license that adds a branded cover page to the exported PDF, so you can try this out without the investment. They have great Ruby support and there''s a Rails gem for it, IIRC. (Not related to them, just an enthusiastic user.) Walter> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, thought I''d chime in on this issue - as I''ve done a _lot_ of PDF-ing I took the Flying Saucer (see link below) - and baked in a little barcode sweetness - but alas it is far from public domain worthy code (read: no tests, no documentation and spaghetti-code) :( but, in short - I call model.html2pdf path_to_template the html2pdf is a mixin on models that require the print-feature the mixin renders the path_to_template with ERB, HAML or what-not - to a tmp-file and then forks a child-process which does a system "build_pdf %tmpfile pdffile.pdf" The build_pdf is essentially the flying saucer java getting executed Don''t know if that helped at all, but it produces nice PDF :) Cheers, Walther http://flyingsaucerproject.github.com/flyingsaucer/r8/guide/users-guide-R8.html Den 22/05/2012 kl. 17.00 skrev Marc C.:> Hello, > > I''m writing a mail-merge application with Ruby on Rails. I have one > user-created template, wich he creates with a CKEditor (in HTML). I have > a list of members, and in the "mailings" controller I mix the template > with the members data to create a PDF with a letter to every member. > This is all working correctly... Except one part: I don''t know how to > render correctly the HTML in the PDF file. > > Currently I use the Prawn library to create the PDF''s. The generation of > the PDF is very easy, but it doesn''t render the HTML codes, so if in the > template appears something like "<b>Hello Mr. {NAME}</b>", in the final > PDF appears the same text, and not "Hello Mr. {NAME}" in bold... > > How can I create PDF''s with Prawn from HTML formatted templates? If it > isn''t possible, which PDF library can I use? I''m using Rails 3.2. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I use PDFKit https://github.com/pdfkit/PDFKit 2012/5/22 Marc C. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> Hello, > > I''m writing a mail-merge application with Ruby on Rails. I have one > user-created template, wich he creates with a CKEditor (in HTML). I have > a list of members, and in the "mailings" controller I mix the template > with the members data to create a PDF with a letter to every member. > This is all working correctly... Except one part: I don''t know how to > render correctly the HTML in the PDF file. > > Currently I use the Prawn library to create the PDF''s. The generation of > the PDF is very easy, but it doesn''t render the HTML codes, so if in the > template appears something like "<b>Hello Mr. {NAME}</b>", in the final > PDF appears the same text, and not "Hello Mr. {NAME}" in bold... > > How can I create PDF''s with Prawn from HTML formatted templates? If it > isn''t possible, which PDF library can I use? I''m using Rails 3.2. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Fernando Almeida www.fernandoalmeida.net -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marc C. wrote in post #1061690:> Except one part: I don''t know how to > render correctly the HTML in the PDF file. > > Currently I use the Prawn library to create the PDF''s.I use Prawn to generate pdf''s, Nokogiri to parse the html portion and created an element_to_pdf method to walk the html, looking for tags to respond to, constructing the pdf.text statements to execute based on the tag encountered. Something like: doc = Nokogiri::HTML(text) children = doc.children[1].children[0].children # doc / html / body / elements children.each do |child| element_to_pdf pdf, child end or something like that... code isn''t at hand -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.