create_pdf

This commit is contained in:
Andreas Stephanides
2015-04-26 18:08:46 +02:00
parent 408a32ae5f
commit d56d77daef
10 changed files with 96 additions and 3 deletions

View File

@@ -52,6 +52,10 @@ def get_theme
#else #else
"blue1" "blue1"
#end #end
end
def current_ability
@current_ability ||= Ability.new(current_user, request)
end end
def default_url_options def default_url_options
{locale: I18n.locale, theme: (theme_name=="blue1") ? nil : theme_name , ansicht: nil} {locale: I18n.locale, theme: (theme_name=="blue1") ? nil : theme_name , ansicht: nil}

View File

@@ -25,6 +25,14 @@ class DocumentsController < ApplicationController
end end
end end
def show
@document = Document.find(params[:id])
respond_to do |format|
format.pdf { send_file @document.create_pdf.path }
format.html
end
end
def dump_to_etherpad def dump_to_etherpad
@document = Document.find(params[:id]) @document = Document.find(params[:id])
@document.dump_to_etherpad @document.dump_to_etherpad

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
class Ability class Ability
include CanCan::Ability include CanCan::Ability
def initialize(user) def initialize(user,request=nil)
loggedin=!(user.nil?) loggedin=!(user.nil?)
user ||= User.new # guest user (not logged in) user ||= User.new # guest user (not logged in)

View File

@@ -26,6 +26,27 @@ class Document < ActiveRecord::Base
def self.ether def self.ether
EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/srv/etherpad/etherpad-lite/APIKEY.txt')) EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/srv/etherpad/etherpad-lite/APIKEY.txt'))
end end
def create_pdf
require "open3"
#url=blank_document_url({id: self.id, host: host, port: port})
# url=Rails.application.routes.url_helpers.blank_document_url({id: self.id, host: host, port: port})
file = Tempfile.new(['document', '.pdf'])
bin=Rails.application.config.pdf_bin
sin,sout,serr=Open3.popen3("#{bin} --header-html \"file://#{Rails.root}/app/views/documents/header.html\" --footer-html \"file://#{Rails.root}/app/views/documents/footer.html\" --replace title1 \"#{self.name}\" - #{file.path}")
#Rails.logger.puts("#{bin} --header-html \"file://#{Rails.root}/app/views/documents/header.html\" --footer-html \"file://#{Rails.root}/app/views/documents/footer.html\" --replace title1 \"#{self.name}\" \"#{url}\" \"#{file.path}\" ")
# `#{bin} --header-html "file://#{Rails.root}/app/views/documents/header.html" --footer-html "file://#{Rails.root}/app/views/documents/footer.html" --replace title1 "#{self.name}" #{url} #{file.path} `
sin.puts("<h1>#{self.name}</h1>")
t=self.text
t.gsub!(/src="[\.\/]*(uploads[^"]*)"/){|s| "src=\"#{Rails.root}/public/"+$1.to_s+'"'}
sin.puts(t)
sin.close
Rails.logger.puts(serr.read)
file
end
def ether def ether
if @ep.nil? if @ep.nil?
@ep=Document.ether @ep=Document.ether

View File

@@ -0,0 +1,29 @@
<!doctype html>
<html><head><script>
function subst() {
var vars={};
var x=document.location.search.substring(1).split('&');
for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}b
</script></head>
<body onload="subst()" style="height:60px;overflow:hidden;"><table style="width:100%">
<tr>
<td style="width:100px">
<img src="logo2014_64.png" style="float:left"/>
</td>
<td style="valign:bottom; text-align:center">
Fachschaft Elektrotechnik - Service-Offizielles-Freizeit
</td>
<td style="text-align:right;width:100px"><span class="page"></span>
</td>
</tr>
</table>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<!doctype html>
<html><head><script>
function subst() {
var vars={};
var x=document.location.search.substring(1).split('&');
for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script></head>
<body onload="subst()" style="height:100%;overflow:hidden; margin:0; padding:0; padding-top:1em;padding-bottom:1em">
<table style="width:100%; ">
<tr>
<td style="width:50px">
</td>
<td style="text-align:center">
<span class="title1"></span>
<span class="page"></span>
</td>
<td style="width:50px">
</td>
</tr>
</table>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -22,5 +22,6 @@
</ul> </ul>
<% end %> <% end %>
<div class="hidden-print">
<%= render_attachments_for(@document) %> <%= render_attachments_for(@document) %>
</div>

View File

@@ -0,0 +1,2 @@
#Fetsite::Application.config.pdf_bin="~/www/wkhtmltopdf/bin/wkhtmltopdf"
Fetsite::Application.config.pdf_bin="wkhtmltopdf"

View File

@@ -192,7 +192,7 @@
get :write_etherpad get :write_etherpad
get :read_from_etherpad get :read_from_etherpad
get :dump_to_etherpad get :dump_to_etherpad
end end
end end
resources :meetings do resources :meetings do
member do member do