NewTOCEntry.label = "\(streamId) page \(pageNum)" Let newDest = PDFDestination(page: pdfPage, at:topLeft) Let destination = PDFDestination(page: pdfPage, at: topLeft) Let topLeft = NSMakePoint(pdfPageRect.minX, pdfPageRect.height + 20) Let pdfPageRect = pdfPage.bounds(for: diaBox)
PDFOUTLINER CODE
ADD A LITTLE CODE TO MAKE THE NSPoint IN THE DESTINATION MORE SOUND Let pdfPage = newPDF.page(at: pageNum-1)!
PDFOUTLINER PDF
NewPDF.outlineRoot = PDFOutline() // CREATE PDF OUTLINE ROOT NODE! And of course the double loop can now be removed, but for clarity's sake I left it in: static func mergePagesIntoSinglePDF(streamId: String, numPages: Int) I also added a little to make the NSPoint a little smarter, since you can't really assume in PDF that the "1,1 " hack is a valid coordinate (generally is. The main problem was that I needed to create a root node for the PDFOutline. Let fileURL = URL(string: directoryURLStr)Īppears that I was much closer than I thought. NewPDF.outlineRoot?.insertChild(newTOCEntry, at: pageNum-1)ĭirectoryURLStr = (getFileURL(streamId: streamId)?.absoluteString)! pdfoutline reads input file given as first argument, adds outlines from text file given as second argument. NewTOCEntry.label = "This is page: \(pageNum)" pdfoutline input.pdf outlines.txt output.pdf. Let newTOCEntry:PDFOutline = PDFOutline.init() Let newDest:PDFDestination = PDFDestination.init(page: newPDF.page(at: pageNum-1)!, at:NSPoint(x:1,y:1)) NewPDF.insert(pdfPage, at: newPDF.pageCount)
If let pdfDocument = PDFDocument(url: directoryUrl!), Let directoryUrl = getFileURL(streamId: streamId, recNum: pageNum)ĭirectoryURLStr = directoryUrl!.absoluteString static func mergePagesIntoSinglePDF(streamId: String, numPages: Int) Ultimately will just have one loop if possible. any leads would be greatly appreciated.īTW, the reason it's in two loops rather than one was because I thought maybe I needed to add all pages first - but trying that didn't make a difference. It might be as simple as a missing assignment or something. The PDF comes out fine but there is never an outline/TOC in it. Note that the table of contents generated by PDFOutliner is NOT printed on a page in the PDF. It works on PDF reading apps on both desktop and mobile.
The table of contents (TOC) shows up in the sidebar of a PDF reader application, and is a handy way to navigate through a PDF. Using best guess on the documentation I came up with the following which I've been twiddling w/a bit but no luck at all. PDFOutliner allows you to add and edit a table of contents in a PDF. I'm working in Swift4/MacOS/Cocoa and can not for the life of me find any kind of example in Swift for creating an outline / only traversing an existing one (which I'm well familiar with). I'm working on a small routine that takes a number of single page PDFs and merges them together into one multi-page PDF.