prawnpdf / pdf-core

Implements low level PDF features for Prawn (experimental)
Other
23 stars 38 forks source link

failed to allocate memory #28

Closed rajeevkannav closed 8 years ago

rajeevkannav commented 8 years ago

pdf-core-0.6.1/lib/pdf/core/stream.rb:21:in `<<'


Backtrace:

shared/bundle/ruby/2.3.0/gems/pdf-core-0.6.1/lib/pdf/core/stream.rb:21:in `<<'
  /home/deploy/figs/shared/bundle/ruby/2.3.0/gems/pdf-core-0.6.1/lib/pdf/core/reference.rb:36:in `<<'
shared/bundle/ruby/2.3.0/gems/prawn-2.1.0/lib/prawn/images/png.rb:169:in `build_pdf_object'
shared/bundle/ruby/2.3.0/gems/prawn-2.1.0/lib/prawn/images.rb:93:in `build_image_object'
shared/bundle/ruby/2.3.0/gems/prawn-2.1.0/lib/prawn/images.rb:66:in `image'
pointlessone commented 8 years ago

@rajeevkannav

Could you please provide a minimal code example that demonstrates your issue and specification of the machine you're having the issue on?

rajeevkannav commented 8 years ago

This is not exact one but it seems like that, I am doing convert command in between prawn - processing . Using Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-47-generic x86_64)

              total        used        free      shared  buff/cache   available
Mem:           1998        1193         591           8         214         747
Swap:             0           0           0
pdf = Prawn::Document.new(skip_page_creation: true, margin: PAGE_MARGINS, info: meta_info)

a_records.collect.with_index do |a_record, index|

  pdf.start_new_page(size: a_record.page_size(self.scale))

  a_record.perform_on_result_100p_png do |a_record_path|
    `convert #{a_record_path} -resize #{scale}%  #{a_record_path}`
    pdf.image open(a_record_path), at: a_record.left_top(scale)
  end

  in_a_loop do
    pdf.svg self.stamp_for_prawn, at: self.left_top(scale)
  end

  a_record.dimensionized_links_selected(target_id: a_records.collect(&:id)).each do |link|
    pdf.link_annotation([
                            link[:left],
                            (a_record.height.to_f - link[:top]),
                            (link[:left] + link[:width]),
                            (a_record.height.to_f - (link[:top] + link[:height]))
                        ], Dest: "a_record-#{link[:i_et].token}")

  end
  pdf.add_dest(a_record.name_tree_destination, pdf.dest_fit(pdf.page))
end
pdf.render_file(temp_file = Tempfile.new([title, '.pdf']))
pointlessone commented 8 years ago

Are there many a_records? Are images in them big?

rajeevkannav commented 8 years ago

Yes.

On Tue, Nov 22, 2016 at 2:41 PM, Alexander Mankuta <notifications@github.com

wrote:

Are there many a_records? Are images in them big?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/prawnpdf/pdf-core/issues/28#issuecomment-262186205, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUQM18bycAJMCnHF37sQXy0L0UdYo7dks5rArHfgaJpZM4K4K3O .

Rajeev Kannav Sharma http://www.google.com/search?q=Rajeev+Kannav+Sharma&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

pointlessone commented 8 years ago

Well, there you go. We know that Prawn is not the most memory-efficient library. But we have no control over how you use it. Give enough big images any library would outgrow any amount of memory.

As a workaround I would suggest generating many one-page PDFs and then stitching them together with convert or any of many specialized CLI tools.

I will close this issue now as this is not a pathological case. Feel free to reopen if you have any additional information or Prawn demonstrably uses disproportionate amounts of memory.