gettalong / hexapdf Goto Github PK
View Code? Open in Web Editor NEWVersatile PDF creation and manipulation for Ruby
Home Page: https://hexapdf.gettalong.org
License: Other
Versatile PDF creation and manipulation for Ruby
Home Page: https://hexapdf.gettalong.org
License: Other
Does HexaPDF currently support any versions of JRuby?
Sharing this in-case someone else needs it:
require 'hexapdf'
class Documentation::DocumentsController < Documentation::BaseController
def show
@document = Document.find(params[:id])
data = open(@document.file_url)
# construct pdf object
pdf = HexaPDF::Document.new(io: data, config: {name: 'asdf'})
pdf.trailer.info[:Title] = @document.title
# write it to a new stream
stream = StringIO.new
pdf.write(stream)
stream.rewind # reset the stream pointer to beginning
# send stream's data as pdf
send_data(stream.read.force_encoding('BINARY'),
disposition: data.meta['content-disposition'],
type: data.meta['content-type'])
end
end
Hello!
Could you please provide an example/sample code of adding the annotations to existing pdf?
Thank you in advance.
Hello,
I was hoping you might be able to provide me with a little help. I've run into a segmentation fault while using you gem on both versions 0.5.0 and 0.6.0. I've attached 2 different segfaults.
I was able to run my job manually in a rails console without any issues.
I'm using the latest version of sidekiq (5.0.5).
The task being performed is taking a pdf and stamping another pdf onto it (one that is blank but has a header/footer banner).
I'm unsure if this is a sidekiq issue or if it's an issue with HexaPDF.
Any suggestions you have would be great!
hexapdf_segfault1.txt
hexapdf_segfault2.txt
If you need more information, I'd be glad to try to get that for you.
Hi there, thanks for this package - it's a blessing.
Just noticed a breakage during the update from 0.7.0
to 0.8.0
.
Failure/Error:
box = HexaPDF::Layout::TextLayouter.create(sanitize(content),
width: max_width,
font: canvas.font,
fill_color: canvas.fill_color)
NoMethodError: undefined method `create' for HexaPDF::Layout::TextLayouter:Class
It looks as though in bff346a HexaPDF::Layout::TextLayouter.create
was removed and internal uses were changed to HexaPDF::Layout::TextFragment.create
. I'm not sure if this is a drop-in replacement for the former method or not, but there is no mention of that method specifically in the CHANGELOG.
Hey guys, I'm getting the error: NoMethodError: undefined method `downcase' for nil:NilClass when trying to generate a new pdf document by adding a page from another.
The same problem occurs when I'm running the 'Hello World' example.
Bellow the code that I'm trying to run:
file = "./filepdf.pdf"
pdf = HexaPDF::Document.open(file)
page1 = pdf.pages.page(1)
doc = HexaPDF::Document.new
doc.pages.add_page(page1)
doc.write("./newpdf.pdf")
I have tried with different pdf files. And get the same respose.
the version of the library installed is: hexapdf (0.1.0)
The complete error message is:
NoMethodError: undefined method 'downcase' for nil:NilClass from /usr/local/bundle/gems/hexapdf-0.1.0/lib/hexapdf/serializer.rb:91:in
block (2 levels) in initialize'`
Somebody knows if there is a problem in the library?
Hi
I am trying to render text in multiple lines, but am getting an error about missing TextLayouter class.
[UPDATE]: I figured its using the textbox class. Can you please update your examples as they are still referring to TextLayouter
Just a question.
Can I work with foreign(URL) files or I can use just local files?
Thanks
is it possible to create a pdf out of an html file or html code using hexapdf?
Hello,
I'm trying to create a new PDF out of selected pages from multiple other PDFs. Your merge functionality works beautifully but ideally I'd really like to be able to split out pages and merge them without having to manually download them and use a desktop tool for the page extraction part. Do you support this functionality? I wasn't able to find it in your docs but I wanted to double check.
Thank you!
Hi @gettalong , Can we use background image on hexapdf?
I'd like to add background image and overwrite a text as like attached pdf file.
207 Sanderling Ln - JSP.pdf
It is possible with this gem?
Hello! I'm having issues inserting images into a merged HexaPDF document.
Context:
I'm currently creating a new HexaPDF document and then creating a couple pages with it (title page/table of contents) and am then merging pdf's into this document.
The last step is where I then loop every page of the document and add a header/footer. Here is where my issue starts. When I try to insert an image into the header or footer, it gives me the error message undefined method `[]' for #<HexaPDF::Object [12, 0] value=[:Pattern, :DeviceRGB]>
.
After debugging the code, I had made it through the image insert to this block of code within the DocumentUtils
:
def each_image(&block)
images = @document.each(current: false).select do |obj|
next unless obj.kind_of?(HexaPDF::Dictionary)
obj[:Subtype] == :Image && !obj[:ImageMask]
end
masks = images.each_with_object([]) do |image, temp|
temp << image[:Mask] if image[:Mask].kind_of?(Stream)
temp << image[:SMask] if image[:SMask].kind_of?(Stream)
end
(images - masks).each(&block)
end
And the failure comes from this lie: obj[:Subtype] == :Image && !obj[:ImageMask]
The thing is, I tried running the lines directly after this loop and the image gets inserted into the document correctly.
Any help here would be much appreciated!
Hello,
Thank you for HexaPDF it's an awesome tool!
I am just wondering if HexaPDF will help me on a specific task. For example I have a 4 Letter Size PDF's 8.5"x11" (1 page posters) but I want to use HexaPDF to create a one big page PDF 17"x22" with a grid of the four individual pdfs displayed on the one larger pdf.
Hello,
I'd like to first thank you for creating this library. It's incredibly well-documented and very well-written!
As title said, I have a question about closing that font file. In the docs you mentioned that The file object representing the font file is not closed and if needed must be closed by the caller once the font is not needed anymore.
I'm wondering how I can get to that file object in order to close it before it might become a problem.
I'm wondering if there is a way to set the different box sizes like Media, Bleed, Trim, and Crop?
Thanks!
@gettalong Can I raise a PR for the same ? I have completed that set of work and if you want I can help other people too by collaborating in this repo. I used this gem and enhanced it for allowing ability to put an image at any of the text location. i.e People can use text as a placeholder to replace it by any image.
We are building prawn based pdf documents that cat get quite long.
I've sorted out a table of contents page that lists the page number of the following sections. It works by storing the page numbers in a hash, then creating the table of contents at the very end. So far so good.
Linking from one page to another is doable as well. What prawn can't do is a print friendly anchor link, like "See page 42 for more info"
. Whatever is on page 42 hasn't been created yet.
What makes me think hexapdf could help with it is reopening and modifying existing pages. My dream would be some kind of gsub
where I replace a placeholder reference with the actual page number after all the pages are streamed out.
I hope this makes some sense. I'm very glad there is a very active pdf tool for ruby.
Given an encrypted pdf and password, is it possible to decrypt and and make a copy given this library?
Apologies if this has been answered; I just didn't see it if so!
Hi thomas,
I've updated my gem to 0.2.0 lately for test-demo, but I'm stuck on the "add_page" method.
require 'hexapdf'
doc = HexaPDF::Document.new
canvas = doc.pages.add_page.canvas
I got this error message:
NoMethodError: undefined method `add_page' for #HexaPDF::Document::Pages:0x007fe72d065b00
from (irb):3
Worked fine then suddenly I get this error:
HexaPDF::Error (Validation error: Required field BaseFont is not set)
Can't find anything about it.
Thanks!
Hi, I've tried merge document with next steps
target = HexaPDF::Document.new
['/path/to/my/file.pdf')].each do |file|
pdf = HexaPDF::Document.open(file)
pdf.pages.each_page {|page| target.pages.add_page(target.import(page))}
end
target.write("merging.pdf", optimize: true)
but it raise:
NoMethodError: undefined method `downcase' for nil:NilClass
from /my/path/gems/hexapdf-0.1.0/lib/hexapdf/serializer.rb:91:in `block (2 levels) in initialize'
I've spent some time looking through the documentation and haven't been able to find this out:
Is it possible to use Hexapdf export a page of a PDF as a PNG (eg for generating a thumbnail) or do I have to use ImageMagick to do this?
Hello!
I want to get pictures from the PDF file to format them. I need their binary contents. Is it possible to get binary contents of images of PDF file using HexaPDF?
Thank.
I've read through the documentation but haven't found a way to do so, so as a last resort, I'm asking here.
In older versions of Prawn (0.12) you could start with an existing PDF as a template, and add text/etc on top of it. Does/will hexapdf support this?
I'm looking for help with converting an AcroForm PDF to a read-only PDF by "flattening" the annotations (specifically, the form fields). I can get the result I want using print-to-PDF in various PDF reader apps. By any chance does HexaPDF have any support for such an operation, or will I need to process the PDF file myself?
If I must do the processing myself, can you offer any advice? Is it just a matter of converting Annotation objects into equivalent text/graphic objects with the same bounding box, font, etc.? That should be straight-forward for text, but I'm not sure how to handle, e.g., the Appearance dictionary for checkboxes.
Any assistance would be greatly appreciated, thanks ...
Hello,
First of all, congratulations for the gem. It's impressive the amount of work that you've put in this project!
More than an issue, it's a question. We are trying to replace pdf-reader
with hexapdf
at factorialhr.com. We have a functionality that reads payslips and extracts information from it. pdf-reader
sometimes does not return us the data correctly, information is missing.
I've tried to replace it like this:
# Original code
reader = PDF::Reader.new(StringIO.open(document.file.read))
@text = reader.pages.join.split("\n")
# HexaPDF code
class SampleProcessor < HexaPDF::Content::Processor
attr_reader :text
def initialize()
super()
@text = ['']
end
def show_text(str)
@text << decode_text(str)
end
alias :show_text_with_positioning :show_text
end
reader = HexaPDF::Document.new(io: StringIO.open(document.file.read))
processor = SampleProcessor.new
reader.pages.each do |page|
page.process_contents(processor)
end
@text = processor.text
Does not seem to be right, but I'm not sure I understand how else to do it. Also, If I comment out the alias :show_text_with_positioning :show_text
it misses plenty of text (the one that is positioned) but if I have it appears in a different ordering.
Am I missing something big?
Is there any support for outlines (bookmarks) in the current version? In my application I am using Prawn and would love to try to switch to hexapdf, which seems to have much better support for merging documents. However, outline creation seems not to be supported yet.
I'd love to extend hexapdf with support for outline creation, but before I start I would like to know if anyone has arguments against having that functionality in hexapdf.
Hello,
The benchmarks are documented with READMEs, but it seems most of them need some input files (e.g., benchmark/line_wrapping/hexapdf.rb
).
Could you add a link to these input files?
Or maybe a script could automatically download them?
Hi @gettalong , I'm not able to use the "write" method on a document object. It always raises this exception:
NoMethodError:` undefined method `downcase' for nil:NilClass
from ...gems/hexapdf-0.1.0/lib/hexapdf/serializer.rb:91:in `block (2 levels) in initialize'
I'm getting this even copying your Hello World example.
Thanks!
I get this with a lot of PDF's that I'm testing with. Not sure what it means.
HexaPDF::Error (Validation error: Type of field D is invalid: String)
Thanks
I have succeeded in drawing a multiple images onto a single-page pdf and then saving it.
hash = {
input_pdf_path: Rails.root.join('spec/fixtures/single_page_pdf.pdf').to_s,
output_pdf_path: Rails.root.join('spec/fixtures/output.pdf').to_s,
signature: [
{
path: Rails.root.join('spec/fixtures/transparent_signature.png').to_s,
coords: [124, 228],
height: 20,
page: 0
},
{
path: Rails.root.join('spec/fixtures/transparent_signature.png').to_s,
coords: [124, 528],
height: 20,
page: 0
}
]
}
doc = HexaPDF::Document.open(hash[:input_pdf_path])
hash[:signature].each do |sig|
page = doc.pages[sig[:page]]
canvas = page.canvas({ type: :overlay})
canvas.xobject(sig[:path], at: sig[:coords], height: sig[:height])
end
doc.write(hash[:output_pdf_path])
My challenge is drawing the same image on multiple pages in a multiple-page pdf. I get a"Validation error: Required field BBox is not set" at the point of writing. Could you tell me what I'm doing wrong? The code below illustrates the failing logic:
hash = {
input_pdf_path: Rails.root.join('spec/fixtures/multi_page_pdf.pdf').to_s,
output_pdf_path: Rails.root.join('spec/fixtures/output.pdf').to_s,
signature: [
{
path: Rails.root.join('spec/fixtures/transparent_signature.png').to_s,
coords: [124, 228],
height: 20,
page: 0
},
{
path: Rails.root.join('spec/fixtures/transparent_signature.png').to_s,
coords: [124, 528],
height: 20,
page: 1
}
]
}
doc = HexaPDF::Document.open(hash[:input_pdf_path])
hash[:signature].each do |sig|
page = doc.pages[sig[:page]]
canvas = page.canvas({ type: :overlay})
canvas.xobject(sig[:path], at: sig[:coords], height: sig[:height])
end
doc.write(hash[:output_pdf_path])
Hey! First of all I just wanted to say thank you. This is a fantastics library.
Do you have any support for scaling/resizing pages? I am working on a bates numbering project with existing documents. I'd like to scale a page to say 90% leaving me a 10% margin to tuck a number in the bottom right corner. Could you point me in a direction for this?
Thank you!
Is this possible? The description says PDF manipulation but I only see examples of adding things.
I want to alter the content of any existing PDF and save a modified version of it.
Is it possible to read a text from a GlyphBox and insert a new text in there, or just delete the whole GlyphBox completely?
The code seem to suggest a GlyphBox is immutable, so I'm not sure what would be a best approach to do that.
Raises when calling document.write
TypeError: class or module required
1
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/dictionary_fields.rb" line 220 in kind_of?
2
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/dictionary_fields.rb" line 220 in convert?
3
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/dictionary_fields.rb" line 168 in convert?
4
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/dictionary.rb" line 159 in []
5
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/type/trailer.rb" line 75 in info
6
File "/app/vendor/bundle/ruby/2.5.0/gems/hexapdf-0.7.0/lib/hexapdf/document.rb" line 600 in write
I'd love to contribute some documentation to https://hexapdf.gettalong.org that I think would be useful for new users of the library and newer programmers. What's the best way to get that to you?
Hi. I'm not sure if this is an expected behavior or if I'm doing things incorrectly, but I have a PDF that passes document validation, but raises an exception when I apply one of your examples to it:
# show_char_bboxes.rb with tiny modification:
...
doc = HexaPDF::Document.open(ARGV.shift)
# -----> my line of code
puts "valid: #{doc.validate(auto_correct: true)}"
doc.pages.each_with_index do |page, index|
puts "Processing page #{index + 1}"
processor = ShowTextProcessor.new(page)
page.process_contents(processor)
end
doc.write('show_char_boxes.pdf', optimize: true)
it fails with
valid: true
Processing page 1
...
Processing page 19
/home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/resources.rb:177:in `object_getter': No object called 'Fo6S0' stored under /Font (HexaPDF::Error)
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/resources.rb:147:in `font'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/operator.rb:766:in `invoke'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/processor.rb:348:in `process'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/parser.rb:165:in `parse'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/parser.rb:153:in `parse'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/form.rb:98:in `process_contents'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/processor.rb:367:in `paint_xobject'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/processor.rb:350:in `process'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/parser.rb:165:in `parse'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/content/parser.rb:153:in `parse'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/page.rb:249:in `process_contents'
from ../hexapdf/examples/show_char_bboxes.rb:56:in `block in <main>'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/page_tree_node.rb:204:in `block in each_page'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/page_tree_node.rb:201:in `each'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/type/page_tree_node.rb:201:in `each_page'
from /home/konstantin/.rvm/gems/ruby-2.3.1/gems/hexapdf-0.4.0/lib/hexapdf/document/pages.rb:112:in `each'
from ../hexapdf/examples/show_char_bboxes.rb:52:in `each_with_index'
from ../hexapdf/examples/show_char_bboxes.rb:52:in `<main>'
Is there any way to make sure the doc is valid or, better, to fix it before processing?
Thanks!
doc = HexaPDF::Document.open(file_name)
puts "Blacken strings [#{strings_to_black}], inside [#{file_name}]."
doc.pages.each.with_index do |page, index|
processor = ShowTextProcessor.new(page, strings_to_black)
page.process_contents(processor)
end
/home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/content/color_space.rb:183:in
new': wrong number of arguments (given 1, expected 0) (ArgumentError) from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/type/resources.rb:82:in
color_space'
from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/content/operator.rb:381:in invoke' from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/content/processor.rb:359:in
process'
from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/content/parser.rb:166:in parse' from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/content/parser.rb:154:in
parse'
from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/type/page.rb:262:in process_contents' from blackout.rb:35:in
block in
block in each_page' from /home/priyanshu/.rvm/gems/ruby-2.4.1/gems/hexapdf-0.6.0/lib/hexapdf/type/page_tree_node.rb:203:in
each'each_page' from blackout.rb:33:in
with_index'
Could HexaPDF embed PDF images in the same way in which raster images are embedded in generated PDF?
It would be nice to be able to do
canvas.image("foo.pdf", at: [350, 0], height: 80)
or
canvas.pdf("foo.pdf", page: 1, at: [350, 0], height: 80)
This feature would give HexaPDF support for vector images, a point of differentiation from Prawn, see prawnpdf/prawn#1020.
I'm getting the following error when trying to retrieve the pages
of a local PDF:
HexaPDF::MalformedPDFError: PDF malformed around position : The oid,gen (43,0) values of the indirect object don't match the values (44,0) from the xref
The code:
pdf = HexaPDF::Document.open("/Users/efatsi/Desktop/Ratified.pdf")
pdf.pages.count # this line triggers the error.
The PDF appears mostly normal (desktop icon is slightly different), and opens well enough in other tools, so I'm not sure what this error means. The only other clue I have is that if I open the PDF in Preview, and then export it as a PDF, then that version works. Meaning OSX Preview is able to squash whatever formatting issue there is.
Curious if you had any thoughts as to what might be going on here. Unfortunately I can't share the culprit PDF as it contains sensitive information, but I could try to track down a similarly messed up one if that would help diagnose.
Not really an issue. Just a question for the author of the gem.
I was lead here by a post in Ruby Weekly. And I use Prawn extensively. It looks interesting, but I was wondering if you or someone who used both tools could contrast what are the advantages of using HexaPDF vs Prawn. I was just hoping to find a clear clear of features / advantages of using this vs Prawn or something like WickedPDF ( which is wkhtmltopdf based - although the differences there are obvious)
Thank . you
Hi.
I'm playing with hexapdf and simply can't get the canvas background to change (from white), nor the box (TextLyaouter).
It seems that the API for textbox changed in the past several releases, and examples no longer work. I tried to follow tests, but nothing I try seems to work.
Since I can modify other params - like alignment, the color of the fonts, width, height, etc - it seems I'm not completely off the reservation.
Also when I query fill_color
it seems to have the color I set, it's just not "painting" it on the canvas.
Any suggestsions?
Thank you
When trying to get an enumerator from each_image
, it blows up with a NoMethodError
:
require 'hexapdf'
HexaPDF::Document.open('sample.pdf') do |pdf|
images = pdf.utils.each_image
end
Causes:
/Users/matt.grecar/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/hexapdf-0.1.0/lib/hexapdf/document_utils.rb:88:in `block in each_image': undefined method `[]' for #<HexaPDF::Object:0x007f9d0a339d30> (NoMethodError)
Hello again,
I'm trying to figure out how to rotate pages in a document. Some pages are landscape and the rest are portrait. Just want to turn the landscape pages. I'm trying to figure out how to use the canvas.rotate() to do this by looking at the examples in the hexapdf app and the docs, but I just can't figure it out.
Can you provide some simple code for doing it?
Thanks!
I'm not exactly sure where in my code it's crashing. I think it's when I open the file to get a page count, but I'm not sure if that's exactly where the problem is. It only happens on our production server running Puma. I'm running Passenger locally so I need to do a bit more testing.
Possible Code:
HexaPDF::Document.open(content_file_path).pages.count
Rails Log:
Completed 500 Internal Server Error in 745ms (ActiveRecord: 473.7ms)
HexaPDF::FilterError (Problem while decoding Flate encoded stream: incorrect data check):
hexapdf (0.6.0) lib/hexapdf/filter/flate_decode.rb:86:in rescue in block in decoder' hexapdf (0.6.0) lib/hexapdf/filter/flate_decode.rb:83:in
block in decoder'
Puma Error Log:
/var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:172: [BUG] Segmentation fault at 0x0000000000000014
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0005 p:0012 s:0034 e:000029 BLOCK /var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:172 [FINISH]
c:0004 p:---- s:0026 e:000025 CFUNC :upto
c:0003 p:0123 s:0021 e:000020 BLOCK /var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:171 [FINISH]
c:0002 p:0193 s:0016 E:002420 BLOCK /var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:251 [FINISH]
c:0001 p:---- s:0003 e:000002 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------
/var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:251:in block in png_execute' /var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:171:in
block (2 levels) in png_execute'
/var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:171:in upto' /var/www/api/shared/bundle/ruby/2.5.0/gems/hexapdf-0.6.0/lib/hexapdf/filter/predictor.rb:172:in
block (3 levels) in png_execute'
-- C level backtrace information -------------------------------------------
/usr/local/rbenv/versions/2.5.1/bin/ruby(rb_vm_bugreport+0x7d3) [0x55b7a72264e3] vm_dump.c:703
/usr/local/rbenv/versions/2.5.1/bin/ruby(rb_bug_context+0xd1) [0x55b7a7219bf1] error.c:580
/usr/local/rbenv/versions/2.5.1/bin/ruby(sigsegv+0x42) [0x55b7a7103cf2] signal.c:928
/lib64/libpthread.so.0(0x7f3f8c49c1b0) [0x7f3f8c49c1b0]
/usr/local/rbenv/versions/2.5.1/bin/ruby(rb_str_set_len+0x14) [0x55b7a7125fd4] string.c:1989
/usr/local/rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-linux/zlib.so(zstream_run_func+0x6f) [0x7f3f88157b4f]
/usr/local/rbenv/versions/2.5.1/bin/ruby(rb_thread_call_without_gvl+0x53) [0x55b7a7143423] thread.c:1353
/usr/local/rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-linux/zlib.so(0x8609) [0x7f3f8815a609]
/usr/local/rbenv/versions/2.5.1/lib/ruby/2.5.0/x86_64-linux/zlib.so(0xaff0) [0x7f3f8815cff0]
/usr/local/rbenv/versions/2.5.1/bin/ruby(vm_call_cfunc+0xe1) [0x55b7a7176011] vm_insnhelper.c:1918
/usr/local/rbenv/versions/2.5.1/bin/ruby(vm_exec_core+0x3136) [0x55b7a717f736] insns.def:915
/usr/local/rbenv/versions/2.5.1/bin/ruby(vm_exec+0x7d) [0x55b7a7183f0d] vm.c:1778
/usr/local/rbenv/versions/2.5.1/bin/ruby(invoke_iseq_block_from_c+0x4ac) [0x55b7a7184dac] vm.c:979
/usr/local/rbenv/versions/2.5.1/bin/ruby(invoke_block_from_c_proc+0x174) [0x55b7a7185084] vm.c:1124
/usr/local/rbenv/versions/2.5.1/bin/ruby(vm_invoke_proc+0xd0) [0x55b7a7185170] vm.c:1149
/usr/local/rbenv/versions/2.5.1/bin/ruby(rb_fiber_start+0x151) [0x55b7a71f1d21] cont.c:1428
/lib64/libc.so.6(0x7f3f8b998d00) [0x7f3f8b998d00]
Here is my test code. It takes pdf as input and produces 2 pdf files: one with expected result and another with unexpected:
require 'hexapdf'
class ShowTextProcessor < HexaPDF::Content::Processor
def self.hello_world(canvas)
canvas.fill_color(0)
canvas.stroke_color(0)
canvas.font('Times', size: 20)
canvas.opacity(fill_alpha: 1, stroke_alpha: 1)
canvas.text('Banana', at: [10, 80])
canvas.opacity(fill_alpha: 0.5, stroke_alpha: 0.5)
canvas.text('Banana', at: [10, 70])
canvas.opacity(fill_alpha: 0.005, stroke_alpha: 0.005)
canvas.text('Banana', at: [10, 60])
end
def initialize(page)
super()
@canvas = page.canvas(type: :overlay)
end
def show_text(str)
self.class.hello_world(@canvas)
end
alias :show_text_with_positioning :show_text
end
# Produces expected result
def test1(input_file)
doc = HexaPDF::Document.open(input_file)
ShowTextProcessor.hello_world(doc.pages.first.canvas(type: :overlay))
doc.write(input_file+'.1.pdf')
end
# Produces unexpected result
def test2(input_file)
doc = HexaPDF::Document.open(input_file)
page = doc.pages[0]
processor = ShowTextProcessor.new(page)
page.process_contents(processor)
doc.write(input_file+'.2.pdf')
end
input_file = ARGV.shift
test1(input_file)
test2(input_file)
Results (test1 shows expected result) :
Hi,
I was hoping you can help me with my issue. I tried going through the documentation and API, and I think I just don't understand the PDF specs well enough, but is it possible to use this gem to write into text fields like the one in this pdf? http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf
I want to basically load a pdf, find all the fields and be able to write certain text into each of them.
Thanks,
Laith
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.