Document some instances of 0 vs 1-based page numbering, import cleanup

This commit is contained in:
James R. Barlow
2018-03-23 13:07:31 -07:00
parent 5790dbc085
commit dfeb8812ad
4 changed files with 19 additions and 1 deletions
+9
View File
@@ -107,6 +107,15 @@ def split_pages(input_file, work_folder, npages):
run(args_qpdf, check=True)
def extract_page(input_file, output_file, pageno):
args_qpdf = [
get_program('qpdf'), input_file,
'--pages', input_file, '{0}'.format(pageno + 1), '--',
output_file
]
run(args_qpdf, check=True)
def _merge_inner(input_files, output_file, min_version=None, log=None):
"""Merge the list of input files (all filenames) into the output file.
+1
View File
@@ -53,6 +53,7 @@ def is_iterable_notstr(thing):
def page_number(input_file):
"Get one-based page number implied by filename (000002.pdf -> 2)"
return int(os.path.basename(input_file)[0:6])
+6
View File
@@ -693,6 +693,12 @@ class PdfInfo:
def has_userunit(self):
return any(page.userunit != 1.0 for page in self.pages)
@property
def filename(self):
if not isinstance(self._infile, (str, Path)):
raise NotImplementedError("can't get filename from stream")
return self._infile
def __getitem__(self, item):
return self._pages[item]
+3 -1
View File
@@ -2,14 +2,15 @@
from contextlib import suppress
from shutil import copyfileobj
from pathlib import Path
import sys
import os
import shutil
import img2pdf
import re
import PyPDF2 as pypdf
from PIL import Image
from PIL import Image
from ruffus import formatter, regex, Pipeline, suffix
from .hocrtransform import HocrTransform
@@ -211,6 +212,7 @@ def repair_pdf(
def get_pageinfo(input_file, context):
"Get zero-based page info implied by filename, e.g. 000002.pdf -> 1"
pageno = page_number(input_file) - 1
pageinfo = context.get_pdfinfo()[pageno]
return pageinfo