gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

In a list containing sub-items, sub-items fitted into a new column or page are bulleted erroneously #295

Closed emilyst closed 5 months ago

emilyst commented 5 months ago

Hi, again. After filing #293, I realized you might benefit from knowing about the possible bug we were avoiding by using a table in the first place. This is not an urgent issue, since it can be worked around. I am not even certain if it's a bug or if I've done something wrong.

My original intention had been to create a PDF with a bulleted list. Each list item would contain two sub-items, a "question" and an "answer" (i.e., the output of filling out a survey). The question is always text, but the answer can include text, another list, or even an image.

By using a bulleted list, I was hoping that it would be easy to visually scan for where each group of sub-items began. Unfortunately, I found that if the second sub-item was fitted onto a new column or page, it would spuriously get assigned its own bullet.

This defeated the point of using a list at all. Because of this problem, and because of #293, we've decided for the time being to locate all image content in its own section at the end of the PDF.

I know this is a little tough to visualize, so I've included below a minimal example script, along with a PDF rendered using this script, and the image I've been using for testing. I'm also including a screenshot, in case the PDF nor script render for you as they're rendering for me.


Screenshot 2024-03-19 at 11 30 16
# frozen_string_literal: true

require "hexapdf"

file = File.open("test.pdf", "w+")

HexaPDF::Composer.create(file) do |composer|
  composer.list(item_spacing: 12) do |list|
    10.times do
      list.multiple do |item|
        item.lorem_ipsum
        item.image(File.open("stunning.png"), width: 100)
      end
    end
  end
end

test.pdf


stunning
gettalong commented 5 months ago

Thanks for reporting this - I can reproduce the bug though with a result that is a little bit different from your output (probably due to different HexaPDF versions used):

image

Will let you know once I find the problem.

gettalong commented 5 months ago

I have found the problem and a fix for it:

image

Will test some more and then release a new bug fix version.

emilyst commented 5 months ago

Oh, that's great! Thanks so much for looking into this. (Incidentally, I wonder why my HexaPDF version is so far behind. I should try to figure that out today.)

gettalong commented 5 months ago

@emilyst I pushed version 0.40.0 with the fix for this bug and two others in list box.

emilyst commented 5 months ago

I really appreciate it! This helps a lot.

gettalong commented 5 months ago

No problem :smile:

Please let me know if you come across other such cases, thanks!