Created
August 1, 2021 07:17
-
-
Save gettalong/db1ecc31bfb96540b97489eff47020f0 to your computer and use it in GitHub Desktop.
PDF link modifier script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hexapdf' | |
doc = HexaPDF::Document.open(ARGV[0]) | |
outline = doc.catalog[:Outlines] | |
first_entry = outline[:First] | |
last_entry = outline[:Last] | |
current = first_entry | |
loop do | |
puts current[:Title] | |
puts current[:A][:Next][:URI] | |
# Change the links here | |
current[:A][:Next][:URI] = "https://my.new.url" | |
break unless (current = current[:Next]) | |
end | |
doc.write("#{ARGV[0]}_changed.pdf", optimize: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment