Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some PDF pages cannot be injected with text objects #2

Closed
boazsegev opened this issue Sep 3, 2014 · 9 comments
Closed

Some PDF pages cannot be injected with text objects #2

boazsegev opened this issue Sep 3, 2014 · 9 comments

Comments

@boazsegev
Copy link
Owner

Some PDFs, specifically certain scanned PDF files (usually those with text recognition), cannot be injected with text objects.

The text injected into those PDF pages (I tried numbering the pages) was not rendered - or, as far as I could tell, was rendered as transparent (render mode 3) even when the mode operator (render modes 1 and 2) was present.

Shapes injected into the same pages were rendered correctly.

Seems as if the previous content streams (the ones after which the content is injected) override the later content streams (the injected data).

Reversing the streams order could not be tested, because the white page - although scanned - isn't transparent, so that the content "behind" it could not be observed.

@boazsegev
Copy link
Owner Author

Fixed a related bug that broke the pointer system (the library relies heavily on objects sharing memory space.

Since stumps were secured and copied, it could cause the pointer system to fail when fonts or images were added more then once.

The pointer issue is now fixed, and the injection bug happens less often - but it is still unresolved.

@boazsegev
Copy link
Owner Author

Resolved.

Used a patch to insert a layer of graphics state with default values.

It should work fine with any PDF... at least all the PDF's I tested were stamped correctly.

@donnguyen
Copy link

donnguyen commented Apr 28, 2017

Hi @boazsegev
I am not sure the issue we are facing here is related to this but can you please take a look at these PDF files:
verified_vit_card_pdf_carla_gangi.pdf
verified_First_Aid_Certificate_2016.pdf
We are trying to add some textbox to these PDF files but it just doesn't work (without any error messages and the same code works well with other files).

Thanks

@boazsegev
Copy link
Owner Author

Hi Đôn Nguyễn,

Thank you for opening this issue :-)

I tried opening the files and writing text, but it seemed to have worked on my machine... maybe it's something I'm doing different...? or a different version...?

Which version are you using?

Can you please post an example code that demonstrates the issue?

I'm very busy these next two weeks because these are the last two weeks of this semester at my collage, but I hope I will be able to get a look soon and help you solve the issue.

Thanks again,
Bo.

@boazsegev
Copy link
Owner Author

@donnguyen

Please let me know if you still experience the issue.

Kindly,
Bo.

@donnguyen
Copy link

hi @boazsegev
Thanks for your help! And actually it works fine my side now also. Maybe I used it the wrong way, just changed a single code line, and it works perfectly. But I still couldn't figure out why it happened with some files only.

Again, thank you, @boazsegev 👍

@donnguyen
Copy link

Btw, below is the code that we used:

    watermark = "Text here"
    pdf.pages.each do |page|
      page.textbox "", opacity: 0.7, height: 40, y: 810,
                   box_color: [1,1,1]
      page.textbox watermark, text_valign: :top,
                   font_size: 8, font_color: [0,0,0], height: 15, y: 822,
                   text_align: :center
      page.textbox "Text here again", text_valign: :top,
                   font_size: 8, font_color: [0,0,0], height: 15, y: 812,
                   text_align: :center
    end

And here is the working code:

    watermark = "Text here"
    pdf.pages.each do |page|
      v_position = page.page_size[3]
      page.textbox "", opacity: 0.7, height: 40, y: v_position - 28,
                   box_color: [1,1,1]
      page.textbox watermark,
                   font_size: 8, text_valign: :top, y: v_position - 50
      page.textbox "Text here again",
                   font_size: 8, text_valign: :top, y: v_position - 250
    end

@boazsegev
Copy link
Owner Author

Hi @donnguyen ,

Thanks for keeping me posted!

I think the reason might be that not all PDF files start at Y=0... but the default :y value for the textbook is 0.

I think I'll change the default on the next release, to allow for non-zero / cropped page origin points (i.e., pages that start at 10,10).

Thanks again and good luck,
Bo.

@dukmarcus
Copy link

Hi,
BTW, how to test whether pdf stamped or not successfully? does it raise any kind of exceptions if something happened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants