Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Issue with Full Template #364

Closed
poori opened this Issue · 10 comments

4 participants

@poori

Hi everyone!

Thanks for the awesome gem! I discovered what seems to be a bug and thought I would report it, along with steps to reproduce.

When I try to take a template and save it, it saves without issues but the document gives a "There was a problem reading this document (14)" when opening the document in acrobat reader. However, it is viewable in OSX's previewer. It seems very similar to issue #199.

Below are steps to reproduce:

download candidate pdf: http://www.dhs.wisconsin.gov/forms/advdirectives/F00060.pdf

then run

Prawn::Document.generate("test.pdf", :template => "F00060.pdf") do
#do nothing
end

Then try to open test.pdf, and it gives the error above.

Prawn Version:
gem 'prawn', :git => "git://github.com/prawnpdf/prawn.git" (bundled today)

I also tried this on the file

filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf"

from the manual example http://prawn.majesticseacreature.com/manual.pdf

and this seems to work fine. So it is possibly something that is only an issue with certain pdfs.

I tried going through the file to see differences but I just started learning the very basics of the pdf file format today and I am afraid it is beyond my ken.

@poori

A quick update. I took the same pdf file and did the following, which worked without any issues.

Prawn::Document.generate("/Users/myusername/Desktop/test.pdf", :skip_page_creation => true) do |pdf|

   (1..15).each do |n|
   #I just happened to know this pdf is 15 pages long...
   pdf.start_new_page(:template => filename, :template_page => n)                  
   end
end
@joshjordan

I'll second this, as I ran into it was well.

The workaround @poori posted can be improved with the advice given by @boazsegev in this thread, wherein he determines the number of pages to loop through rather than hardcoding it: #199

In fact, this issue appears to be a continuation of that one, except that it occurs when using Document.new(template) as opposed to start_new_page(template)

Another example document you can use for this case is the Prawn manual itself.

I wonder how many people out there are generating documents with this method and are unaware that Adobe Reader users will choke on some of their PDFs.

@joshjordan

Has anyone thought about the solution to this problem?

We just found that in our production environment, the workaround can consume over a hundred megabytes of memory for a single document. This is prohibitively expensive for scale.

@jonsgreen
Collaborator

Have you tried pointing to the github repo because this has been worked on recently and has been merged into master.

Please report here what you find. Thanks.

@joshjordan

Hi Jon. Thanks so much for your work on this. Unfortunately, I am still seeing "There was a problem reading this document (14)" in Acrobat Reader for generated PDFs. Please let me know if there's anything else I can do to help.

@jonsgreen
Collaborator

Can you post the template that you are using and some sample code to try out?

@joshjordan

Sure thing. Unfortunately, most of the documents I work with are proprietary. I used to be able to reproduce this with the Prawn manual itself, but that is now throwing a NilClass error.

I had a hard time finding a document outside my proprietary document store that failed using the gem as well as Prawn directly from the repo (kudos - many are fixed!). However, I did find one: https://www.dropbox.com/s/1qd6xv9htxkhm1b/Rails_for_Designers_-_Slides.pdf

This is unopenable using Acrobat Reader after generating it like so:

Prawn::Document.new(template: '/Users/jjordan/Dropbox/Rails_for_Designers_-_Slides.pdf').render_file('test.pdf')

@jonsgreen jonsgreen referenced this issue from a commit in jonsgreen/prawn
@jonsgreen jonsgreen Issue #364 Issue With Full Template
only set /Parent reference for page templates to appease Adobe Acrobat
5b6beda
@jonsgreen
Collaborator

joshjordan,

I think I see what the problem is and it has to do with incorrect Parent references of object similar to #199; Adobe just doesn't like that. In fact it was my the fix for that issue that has resulted in this one for full templates.

Anyhow if you could try pointing your Gemfile to my fork: git@github.com:jonsgreen/prawn.git to see if my latest fix solves your problem that would be helpful. Thanks.

@joshjordan
@joshjordan

Jon, I tested this on a large set of documents that previously failed and am happy to report that they are all succeeding with your fix. Thanks again! Let me know if I can be of any assistance getting your work merged into prawn's master branch.

@jonsgreen jonsgreen referenced this issue from a commit in jonsgreen/prawn
@jonsgreen jonsgreen Issue #364 Issue With Full Template
only set /Parent reference for page templates to appease Adobe
Acrobat
correct nested_pages.pdf pages to point to correct parent for Adobe
reader and spec testing purposes
edcc3f6
@practicingruby practicingruby added templates and removed stale labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.