修改 grim 源代码 image_magick_processor.rb 添加 "-flatten", "-background", "white",
def save(pdf, index, path, options)
width = options.fetch(:width, Grim::WIDTH)
density = options.fetch(:density, Grim::DENSITY)
quality = options.fetch(:quality, Grim::QUALITY)
command = [@imagemagick_path, "-resize", width.to_s, "-antialias", "-render",
#"-quality", quality.to_s, "-alpha", "remove", "-colorspace", "RGB",
"-quality", quality.to_s, "-colorspace", "RGB",
"-interlace", "none", "-density", density.to_s,
"-flatten", "-background", "white",
"#{Shellwords.shellescape(pdf.path)}[#{index}]", path]
command.unshift("PATH=#{File.dirname(@ghostscript_path)}:#{ENV['PATH']}") if @ghostscript_path
result = `#{command.join(' ')}`
$? == 0 || raise(UnprocessablePage, result)
end
#1 楼 @krazy 与之相比较 rmagick http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby 哪个比较好啊?比如图片清晰度、效率等等。。
多选框 https://gist.github.com/bradediger/58890
# "☐" "\xE2\x98\x90" "\u2610"
# "☑" "\xE2\x98\x91" "\u2611"
# "☒" "\xE2\x98\x92" "\u2612"
# "font" "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
def checkbox(label, checked)
box = checked ? "\u2611" : "\u2610"
checkbox_font = "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"
"<font name='app/assets/fonts/STSONG.TTF'>#{label}</font><font name='"+checkbox_font+"'>"+box+"</font>"
end
font "app/assets/fonts/STSONG.TTF"
# 如有多选框 并且默认字体是仿宋 会报错 bad font 我只能切换到以前的字体,谁有没有更好的方法
font "Helvetica"
table([
[checkbox("读书",true),checkbox("书法",true),checkbox("绘画",false)]
], :cell_style => {:inline_format => true})
本地
require "fileutils"
data = File.open("#{Rails.root}/../dfs/pdf/a.pdf")
send_data data.read, type: "application/pdf", disposition: "inline", stream: "true"
服务器
require "open-uri"
data = open("http://www....... a.pdf")
send_data data.read, type: "application/pdf", disposition: "inline", stream: "true"
uploader 文件
def store_dir
#"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
"#{Rails.root}/../dfs/"
end
def extension_white_list
%w(jpg jpeg gif png)
end
def filename
if original_filename
uuid = UUIDTools::UUID.random_create.to_s
uuid_p = uuid.gsub('-','')
@name = file.extension+"/"+uuid_p[1,2]+"/"+uuid_p[4,2]+"/"+uuid_p[7,2]+"/"+uuid_p[10,22]+"."+file.extension
# current_path 是 Carrierwave 上传过程临时创建的一个文件,有时间标记,所以它将是唯一的
"#{@name}"
end
end
恩 回车键就挺好用的。。或者 gsub('\n',"\n") 用用这个 Crack 谢谢各位
新建一个 table 怎么判断这个 table 是否在一页 不在一页的话 新建一页建立 table?
Prawn::Document.generate("test.pdf") do
repeat :all do
# header
bounding_box [bounds.left, bounds.top], :width => bounds.width do
#font "Helvetica"
#text "Here's My Fancy Header", :align => :center, :size => 25
data = [
["1","2","3"],
["2","3","4"]
]
table(data)
stroke_horizontal_rule
end
# footer
bounding_box [bounds.left, bounds.bottom + 25], :width => bounds.width do
font "Helvetica"
stroke_horizontal_rule
move_down(5)
text "And here's a sexy footer", :size => 16
end
end
bounding_box([bounds.left, bounds.top - 50], :width => bounds.width, :height => bounds.height - 100) do
text "this is some flowing text " * 400
end
end
已解决
Prawn::Document.generate('hello.pdf') do
text("Hello Prawn!")
start_new_page
text("Hello Prawn!")
start_new_page
text("Hello Prawn!")
number_pages "<page> in a total of <total>", :start_count_at => 0, :page_filter => :all, :at => [bounds.right - 100, 0], :align => :right, :size => 25
end
Prawn::Document.generate("#{Rails.root}/../dfs/hello.pdf") do
header margin_box.top_left do
text "Here's My Fancy Header", :size => 25, :align => :center
end
text "hello world!"
end
ActionView::Template::Error (undefined method `header' for #Prawn::Document:0x007fb8e000a820):
prawn 是纯 ruby 代码,可以用 ruby 的各种模块化方式组织,一个简单解决方法是用 load 执行:
load "./pdf_t.pdf.prawn"
怎么修改图片的名字,名字是 uuid 自动生成的。
怎么修改图片的名字,名字是 uuid 自动生成的。
#5 楼 @towonzhou 恩 懂了 谢谢!
项目运行 uri 为(http://192.168.1.239:3000/uuid_test)就不能运行。 换成另一个项目掉用这个接口时 就可以(http://192.168.1.239:3001/uuid) 本项目应该怎么调用 本项目提供的对外接口?
#1 楼 @towonzhou 一直超时。报错超时。百度 uri 能运行。
已解决 就是 session 的问题。谢谢大家
恩 正在尝试中。。有一个修改密码的验证码 是通过 session 保存的。。
def settings
session[:noisy_image] = NoisyImage.new(4) #生成一个有4字符的图片
session[:code] = session[:noisy_image].code
if current_user
@user=current_user
else
@user=User.find(params[:id])
end
end
2013/09/04 09:28:12 [error] 1121#0: *6454 upstream sent too big header while reading response header from upstream, client: 192.168.1.137, server: hmp, request: "GET /settings HTTP/1.1", upstream: "http://unix:/tmp/unicorn.hmp.sock:/settings", host: "192.168.1.7", referrer: "http://192.168.1.7/"