Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created August 26, 2020 00:23
Show Gist options
  • Save bdkosher/118be3cb9aa95c12a58c54c1c8a574c4 to your computer and use it in GitHub Desktop.
Save bdkosher/118be3cb9aa95c12a58c54c1c8a574c4 to your computer and use it in GitHub Desktop.
Adobe's not getting $14 from me just so I can merge some PDF pages together
@Grab(group='org.apache.pdfbox', module='pdfbox', version='2.0.21')
import org.apache.pdfbox.multipdf.PDFMergerUtility
import org.apache.pdfbox.io.MemoryUsageSetting
def dir = new File('C:\\Users\\Joe\\Documents\\pdfs')
def merger = new PDFMergerUtility();
(1..3).each { merger.addSource(new File(dir, "document_page${it}.pdf")) }
merger.destinationFileName = new File(dir, "document.pdf").absolutePath
merger.mergeDocuments(MemoryUsageSetting.setupTempFileOnly())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment