Package: tocPDF
tocPDFThis project was created due to the lack of outlines included with most digital PDFs of textbooks.
This command line tools aims at resolving this by automatically generating the missing outline based on the table of contents.Table of ContentstocPDFTable of ContentsInstallationPIPManuallyInconsistent OffsetUsageExampleSupported FormatsAlternative SoftwareInstallationPIPThe package can be downloaded using pip:pipinstalltocPDFManuallyIt can be installed manually by first cloning the repository:gitclonehttps://github.com/kszenes/tocPDF.gitThen navigate into the base directory (toc-pdf-package) of the project and install the package using pip:pipinstall.This will fetch all the necessary dependencies for running the program as well as install the command line tool.Inconsistent OffsetThe main difficulty with automatically generating outlines for PDFs stems from the fact that the PDF page numbers (displayed by your PDF viewer) do not match the page numbers of the book that you are trying to outline. In addition, certain PDFs will be missing some pages (usually between root chapters) compared to the book. This means that the page difference between the book and the PDF is not consistent throughout the document and needs to be recomputed between chapters. tocPDF can automatically recompute this offset by comparing the expected page number to the one found in the book.UsageThis program requires 3 input parameters: the first and last PDF page of the table of contents as well as the PDF-book page offset. The offset is defined as the PDF page corresponding to the first book page with Arabic numerals (usually the first chapter). If your book has missing pages in between chapter, add the flag--missing_pagesfollowed by either tika or pdfplumber. This will determine the parser used to make sure that the PDF-book page offset is still correct. Note that this option will make the outline creation much more robust however the execution time will be a bit slower. If your PDF is not missing any pages you can omit this flag.Usage:tocPDF[OPTIONS]FILENAMEGeneratesoutlinedPDFbasedontheTableofContents.Version:0.3.1Example:tocPDFexample.pdf

Options:-s,--start_tocINTEGERPDFpagenumberofFIRSTpageofTableofContents.[required]-e,--end_tocINTEGERPDFpagenumberofLASTpageofTableofContents.[required]-o,--offsetINTEGERGlobalpageoffset,definedasPDFpagenumberoffirstpagewitharabicnumerals.[required]-m,--missing_pagesTEXTParser(tikaorpdfplumber)usedtoautomaticallydetectoffsetbyverifyingbookpagenumbermatchesexpectedPDFpage.-d,--debugOutputsPDFfile(tmp_toc.pdf)containingthepagesprovidedforthetableofcontents.-h,--helpShowthismessageandexit.ExampleThe CLI can be simply invoked with the PDF as parameter:tocPDFexample.pdfand then the user will be prompted to add the start/end pages of the PDF as well as the offset to the first page of the PDF.These parameters can be directly provided as arguments to the CLI. For instance, the following command generates the correct outlined PDF for the example document found inexample_pdf/example.pdf:tocPDF--start_toc3--end_toc5--offset9--missing_pagestikaexample.pdfOr equivalently:tocPDF-s3-e5-o9-mtikaexample.dfThis will generate a new outlined PDF with the name out.pdf.Supported FormatsThe format for table of contents varies from document to document and I can not guarantee that tocPDF will work perfectly. I have tested it out on a dozen documents and it produces decent results. Make sure to run with both parsers (-m tikaand-m pdfplumber) and compare results. If you have encountered any bugs or found any unsupported table of content formats, feel free to open an issue.Alternative SoftwareIn case the generated outline is slightly off, I recommend using thejpdfbookmarks(can be directly downloaded fromsourceforge) which is a nice piece of free software for manually editing bookmarks for PDFs.