Bugzilla – Attachment 129832 Details for
Bug 104804
Help on "Export Bookmarks" and help on "Export bookmarks as named destinations" is not clear enough
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Python file that lists named destinations....
ListNamedDestinations.py (text/plain), 5.00 KB, created by
crun
on 2016-12-21 03:41:56 UTC
(
hide
)
Description:
Python file that lists named destinations....
Filename:
MIME Type:
Creator:
crun
Created:
2016-12-21 03:41:56 UTC
Size:
5.00 KB
patch
obsolete
>#!/usr/bin/env python ># Sorts and Lists all Named-Destinations in a files >#usage: python ListNamedDestinations.py SomePDFFile.pdf >import sys >from pyPdf import PdfFileReader > >def FlattenList (ListIn, ListOut=None ) : #flattens a nested list > if ListOut is None : > ListOut = dict() > if type(ListIn) == list : > print "ListIn", type(ListIn) > for x in ListIn : > print "x", type(x) > ListOut=FlattenList(x,ListOut) > else : > print type(ListIn) > ListOut.update(ListIn) > #for name in ListIn : > # ListOut[name]=ListIn[name] > return ListOut > >def pdf_get_anchors(fh): > reader = PdfFileReader(fh) > destinations = reader.getNamedDestinations() #completely unsorted order, does not include pagenums ># destinations = reader.getOutlines() #completely unsorted order, does not include pagenums ># print type(destinations) ># destinations = FlattenList(destinations) > L=list() > for PageNum in range(1,reader.numPages+1) : > ThisPage = reader.getPage(PageNum-1) > PageTop = ThisPage['/MediaBox'][3] > for name in destinations: > ThisDest = destinations[name] > print name, ThisDest > ThisDestPage = ThisDest.page.getObject() > if ThisDestPage == ThisPage: #have to do this to identify the pagenum > DownPage = (PageTop - ThisDest.top) / PageTop # calc fraction of page down > Position = PageNum + DownPage # a sortable number down the whole pdf > L.append((name, PageNum, Position)); # put everything in a sortable list > return L, len (destinations), reader.getNumPages() > >def pdf_print_anchors ( L ) : > for dest in L : > name=dest[0] > PageNum=dest[1] > Position= round(dest[2]*100)/100 > print "%-8.2f % %s" % Position % name #ThisDest.title > >HeaderLine="\n Page Name\n" >L, NumDests, NumPages =pdf_get_anchors(open(sys.argv[1],'rb')) > >print HeaderLine >L.sort(key=lambda dest: dest[0]) #sort name order >pdf_print_anchors(L); >print HeaderLine >L.sort(key=lambda dest: dest[2]) #sort in order down the pdf >pdf_print_anchors(L); >print HeaderLine >print "Number of NamedDestinations: ", NumDests, "NumPages: ", NumPages >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 104804
:
129831
| 129832 |
130055
|
130249
|
137940
|
137941