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

Add outline entries for pages in existing PDF files #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

edman193
Copy link

@edman193 edman193 commented Jun 4, 2020

Hi, thanks for this great library. We used it to generate some great reports dynamically and it works very well.

I had the need to generate outline entries dynamically for the documents, and I want to share this functionality.

closes #134

Examples

To generate a single flat outline:

pdf = CombinePDF.new
i = 1
CombinePDF.load("file.pdf").pages.each do |page|
  pdf.add_outline_item(page, "Page #{i}")
  pdf << page
  i += 1
end
pdf.save "outlines.pdf"

Generating a tree hierarchy:

pdf = CombinePDF.new
i = 1
CombinePDF.load("file.pdf").pages.each do |page|
  if i.eql? 1
    pdf.add_outline_grouper(page, 'Section 1')
    pdf.add_outline_grouper(page, 'Subsection 1.1')
  elsif i.eql? 3
    pdf.go_out_outline_grouping_level
    pdf.add_outline_grouper(page, 'Subsection 1.2')
  elsif i.eql? 4
    pdf.go_outline_root
    pdf.add_outline_grouper(page, 'Section 2')
  elsif i.eql? 5
    pdf.go_out_outline_grouping_level
  end

  pdf.add_outline_item(page, "Page #{i}")

  pdf << page
  i += 1
end
pdf.save "outlines.pdf"

This will generate something like:

image

@edman193 edman193 force-pushed the feature/create-outline-entries branch from deeac85 to 3783e48 Compare June 4, 2020 18:42
Add the ability to authoring outline entries from scratch taking
a page and a title as parameters. The outile can be created in a tree
hierarchy.
@edman193 edman193 force-pushed the feature/create-outline-entries branch from 3783e48 to 8b901bb Compare June 4, 2020 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a outline before or after merging pdf
1 participant