Произвольно изменить порядок страниц в документе PDF

1435
synaptik

Я ищу серию команд для рандомизации порядка страниц в существующем документе PDF.

2
См. Также [Как я могу перетасовать страницы из файла PDF в случайном порядке?] (Http://unix.stackexchange.com/q/209637/80216) (в Unix и Linux) G-Man 8 лет назад 0

1 ответ на вопрос

2
synaptik

Turns out, there's a nice python library pyPDF which can be used in the following script to randomize the order of pages in a PDF document.

The script below, call it mixpdf, creates a copy of an input PDF file with randomly reordered pages when called by the statement mixpdf myinputfile.pdf.

#!/usr/bin/python import sys import random from pyPdf import PdfFileWriter, PdfFileReader # read input pdf and instantiate output pdf output = PdfFileWriter() input1 = PdfFileReader(file(sys.argv[1],"rb")) # construct and shuffle page number list pages = list(range(input1.getNumPages())) random.shuffle(pages) # display new sequence print 'Reordering pages according to sequence:' print pages # add the new sequence of pages to output pdf for page in pages: output.addPage(input1.getPage(page)) # write the output pdf to file outputStream = file(sys.argv[1]+'-mixed.pdf','wb') output.write(outputStream) outputStream.close() 

Похожие вопросы