2010-11-27 6 views
2

Je veux générer un fichier PDF à partir d'un document html dans une application rails. J'ai donc décidé d'utiliser wicked_pdf. Mais ça ne marche pas. J'ai essayé de l'intégrer dans une application, mais cela n'a pas fonctionné. J'ai donc pensé à essayer de voir si cela fonctionne dans la console rails puis je vais l'intégrer dans l'application.wicked_pdf ne fonctionne pas - Ruby on Rails

Voici ce que je suis tombé sur la console

wp = WickedPdf.new 
=> #<WickedPdf:0x4e7eea0 @exe_path="C:\\wkhtmltopdf\\wkhtmltopdf.exe"> 
HTML_DOCUMENT = "<html><body>Hello World</body></html>" 
=> "<html><body>Hello World</body></html>" 
pdf = wp.pdf_from_string HTML_DOCUMENT 
"***************C:\\wkhtmltopdf\\wkhtmltopdf.exe - - ***************" 
NotImplementedError: fork() function is unimplemented on this machine 
    from C:/Ruby/lib/ruby/1.8/open3.rb:57:in `fork' 
    from C:/Ruby/lib/ruby/1.8/open3.rb:57:in `popen3' 
    from C:/Users/raw/Desktop/html/scheduler/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:22:in `pdf_from_string' 
    from (irb):3 

MISE À JOUR: J'utilise Windows7

Je ne suis pas en mesure de savoir où je me trompe.

Aidez-nous s'il vous plaît.

Merci d'avance.

Répondre

3

Installez le joyau win32-open3

gem install win32-open3 

Et maintenant changer de ligne: 6 lib/wicked_pdf.rb

require 'open3'

à

require 'win32/open3' 

et ligne: 20 dans le même fichier

command_for_stdin_stdout = "#{@exe_path} #{options} - - -q" 

à

command_for_stdin_stdout = "#{@exe_path} #{options} - -" 

et maintenant dans la console que je reçois

wp = WickedPdf.new 
=> #<WickedPdf:0x4e65f70 @exe_path="C:\\wkhtmltopdf\\wkhtmltopdf.exe"> 

?> HTML_DOCUMENT = "<html><body>Hello World</body></html>" 
=> "<html><body>Hello World</body></html>" 

?> pdf = wp.pdf_from_string HTML_DOCUMENT 
"***************C:\\wkhtmltopdf\\wkhtmltopdf.exe - - ***************" 
=> "%PDF-1.4\n1 0 obj\n<<\n/Title (\376\377)\n/Producer (wkhtmltopdf)\n/CreationDate (D:20101127124137)\n>>\nendobj\n4 0 obj\n<<\n/Type /ExtGState\n/SA true\n/SM 0.02\n/ca 1.0\n/CA 1.0\n/AIS false\n/SMask /None>>\nendobj\n5 0 obj\n[/Pattern /DeviceRGB]\nendobj\n8 0 obj\n<<\n/Type /Catalog\n/Pages 2 0 R\n>>\nendobj\n6 0 obj\n<<\n/Type /Page\n/Parent 2 0 R\n/Contents 9 0 R\n/Resources 11 0 R\n/Annots 12 0 R\n/MediaBox [0 0 595 842]\n>>\nendobj\n11 0 obj\n<<\n/ColorSpace <<\n/PCSp 5 0 R\n/CSp /DeviceRGB\n/CSpg /DeviceGray\n>>\n/ExtGState <<\n/GSa 4 0 R\n>>\n/Pattern <<\n>>\n/Font <<\n/F7 7 0 R\n>>\n/XObject <<\n>>\n>>\nendobj\n12 0 obj\n[ ]\nendobj\n9 0 obj\n<<\n/Length 10 0 R\n/Filter /FlateDecode\n>>\nstream\nx\234\245\222QKÄ0\f\200ßó+ò,\×6ëÖ‚øàPÁa\254àƒø ;O9\274Ãy\017\376}ÓtÇ�\003\213`ÖåKÒ\264ɪ\273áß\016XuÃ'\216\263îÐJ\273\220\027j\226ÕX\257Èê\264ÐRM+tÜÁ\204\023ôÐó;é Ž\273j\221ø\207*×›\243\022Ý�\017\r)ÞÁ\023\233\037K\223È©`\264v\236\271>7Sð;<^à¾Xêè1\"KÏA\271ÐÖ\244\255\225\2643\223o$\224j$\207_\257\260IçþKÚï\247Édèøë-Þó\263ŧg\206ëâ5\256#T\267-\032\217qÃ÷\220\241d\025\271\205\270\2625Æ5^òPÌÆ-\230䜉\025\022N\200\004P\001Ôç)[email protected]}\002M.ã 
9\255\000W(ãÜDil\376qLî¢ùo3Ó ÊØÃ\0177Ч\201endstream\nendobj\n10 0 obj\n271\nendobj\n13 0 obj\n<< /Type /FontDescriptor\n/FontName /QNAAAA+ArialRegular\n/Flags 4 \n/FontBBox [-594.726562 -290.527343 1790.03906 900.390625 ]\n/ItalicAngle 0 \n/Ascent 651.367187 \n/Descent -188.476562 \n/CapHeight 0 \n/StemV 65.4296875 \n/FontFile2 14 0 R\n>> endobj\n14 0 obj\n<<\n/Length1 3840 \n/Length 17 0 R\n/Filter /FlateDecode\n>>\nstream\nx\234\245W]l\024×>wgg×C0ÆkW\204p\rÄ?\024l\263Æ»ÆÄ8ÈD\245\030cc\e\0220\224\214wf\275cvgV\263\263^\257\241\205\2406BQ#\245\205\246\025êC‰\2226I[~ÒÚ”\246\250M\245<\264\225ÒH\225\252\242ÊM\213\232\206(U\037\"\265Ä?=÷ÜYgL(RÕ]Í�ïœ{î9ßùæÞY\030\000\224ÁiP\000ú‡Z¢+\242Gsèù*^O\216\245\213Ék\237Áø 

Jetez un oeil à this blog post pour le comprendre. Merci.

2

Vous pouvez essayer DocRaptor.com. C'est une application en ligne qui vous permet de convertir html to pdf. Ils ont des comptes gratuits disponibles, plus des comptes payés si vous avez besoin de beaucoup de documents.

Espérons que ça aide!

Julie

+0

Il y a un Ruby Gem ici: https://github.com/expectedbehavior/doc_raptor_gem – Julie

0

créer un dossier dans votre public appelé "pdfs"

Controller:

pdf = render_to_string :pdf => "graphs", :orientation => 'Landscape', :font_size => 11 
# then save to a file 
save_path = Rails.root.join('pdfs', filename.pdf') 
File.open(save_path, 'wb') do |file| 
file << pdf 
end 

graphs.rhtml

Vue: ajouter cette ligne de code pour les styles

<%= wicked_pdf_stylesheet_link_tag "css filename here" %>