• PDF To Image at January 25, 2014

    修改 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
    
  • PDF To Image at January 24, 2014

    #7 楼 @krazy 怎么给图片加一个白色的背景色呢?

  • PDF To Image at January 08, 2014

    #8 楼 @liker 能不能把网上的 pdf 转化为图片呢,而不是本地。

  • PDF To Image at January 06, 2014

    #7 楼 @krazy 还是不行。我用 rmagick 生成的 png 比 jpg 清晰。但是还属 grim 生成的 png 最为清晰。谢谢!

  • PDF To Image at January 06, 2014

    #5 楼 @krazy

    @path = "#{Rails.root}/public/b.png"
    pdf = Grim::Pdf.new("#{Rails.root}/public/a.pdf")
    Grim::ImageMagickProcessor.new.save(pdf,0,@path,{})
    

    生成 png 文件没问题。当生成 b.jpg 时,生成的文件一团黑。

  • PDF To Image at January 06, 2014

    #3 楼 @krazy 用 grim 怎么生成 jpg 文件啊!生成的 png 文件太大,一页大概 170kb。有没有 api 文档

  • PDF To Image at January 06, 2014

    #1 楼 @krazy 与之相比较 rmagick http://stackoverflow.com/questions/65250/convert-a-doc-or-pdf-to-an-image-and-display-a-thumbnail-in-ruby 哪个比较好啊?比如图片清晰度、效率等等。。

  • JS 解析 XML 路径问题 at December 18, 2013

    #1 楼 @huacnlee 恩,配置了一下路由。加上 format: 'xml' 就能访问了

  • #7 楼 @hexawing 我的意思是 比如有一列占了四行,当第二行就分页时,显示的效果特别丑。

  • 多选框 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})
    

  • 渲染服务器 PDF 文件 at December 04, 2013

    本地

    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"
    
  • 渲染服务器 PDF 文件 at December 04, 2013
  • Carriewave 上传图片 at November 29, 2013

    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
    
  • rexml 解析 xml 解析效率 at November 29, 2013

    #3 楼 @Rei 恩恩 谢谢

  • 解析字符串 bug at November 28, 2013

    恩 回车键就挺好用的。。或者 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 自动生成的。

  • carrierwave 使用求解 at October 31, 2013

    怎么修改图片的名字,名字是 uuid 自动生成的。

  • Net::HTTP get 方法 at October 30, 2013

    #5 楼 @towonzhou 恩 懂了 谢谢!

  • Net::HTTP get 方法 at October 29, 2013

    项目运行 uri 为(http://192.168.1.239:3000/uuid_test)就不能运行。 换成另一个项目掉用这个接口时 就可以(http://192.168.1.239:3001/uuid) 本项目应该怎么调用 本项目提供的对外接口?

  • Net::HTTP get 方法 at October 29, 2013

    #1 楼 @towonzhou 一直超时。报错超时。百度 uri 能运行。

  • 502 Bad Gateway nginx/1.1.19 at September 04, 2013

    已解决 就是 session 的问题。谢谢大家

  • 502 Bad Gateway nginx/1.1.19 at September 04, 2013

  • 502 Bad Gateway nginx/1.1.19 at September 04, 2013

    恩 正在尝试中。。有一个修改密码的验证码 是通过 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
    
  • 502 Bad Gateway nginx/1.1.19 at September 04, 2013
    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/"