create_pdf
This commit is contained in:
@@ -52,6 +52,10 @@ def get_theme
|
||||
#else
|
||||
"blue1"
|
||||
#end
|
||||
end
|
||||
|
||||
def current_ability
|
||||
@current_ability ||= Ability.new(current_user, request)
|
||||
end
|
||||
def default_url_options
|
||||
{locale: I18n.locale, theme: (theme_name=="blue1") ? nil : theme_name , ansicht: nil}
|
||||
|
||||
@@ -25,6 +25,14 @@ class DocumentsController < ApplicationController
|
||||
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
|
||||
@document = Document.find(params[:id])
|
||||
@document.dump_to_etherpad
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
class Ability
|
||||
include CanCan::Ability
|
||||
def initialize(user)
|
||||
def initialize(user,request=nil)
|
||||
loggedin=!(user.nil?)
|
||||
user ||= User.new # guest user (not logged in)
|
||||
|
||||
|
||||
@@ -26,6 +26,27 @@ class Document < ActiveRecord::Base
|
||||
def self.ether
|
||||
EtherpadLite.connect('http://www.fet.at/etherpad', File.new('/srv/etherpad/etherpad-lite/APIKEY.txt'))
|
||||
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
|
||||
if @ep.nil?
|
||||
@ep=Document.ether
|
||||
|
||||
29
app/views/documents/footer.html
Normal file
29
app/views/documents/footer.html
Normal 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>
|
||||
28
app/views/documents/header.html
Normal file
28
app/views/documents/header.html
Normal 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>
|
||||
BIN
app/views/documents/logo2014_64.png
Normal file
BIN
app/views/documents/logo2014_64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -22,5 +22,6 @@
|
||||
</ul>
|
||||
<% end %>
|
||||
|
||||
|
||||
<div class="hidden-print">
|
||||
<%= render_attachments_for(@document) %>
|
||||
</div>
|
||||
|
||||
2
config/initializers/pdf_convert.rb
Normal file
2
config/initializers/pdf_convert.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
#Fetsite::Application.config.pdf_bin="~/www/wkhtmltopdf/bin/wkhtmltopdf"
|
||||
Fetsite::Application.config.pdf_bin="wkhtmltopdf"
|
||||
Reference in New Issue
Block a user