MCPcopy Create free account
hub / github.com/bgeron/diff-pdf-visually / pdfdiff_pages

Function pdfdiff_pages

diff_pdf_visually/diff.py:101–248  ·  view source on GitHub ↗

Find visual differences between two PDFs; return the page numbers with significant differences. When the number of pages is different between the PDFs, then return [-1]. Keyword arguments: tempdir: if not None, then this should be a pathlib.Path for an empty writable

(
    a,
    b,
    threshold=None,
    verbosity=None,
    dpi=None,
    tempdir=None,
    time_to_inspect=0,
    num_threads=None,
    max_report_pagenos=None,
)

Source from the content-addressed store, hash-verified

99 return pdf_similar(*args, **kw)
100
101def pdfdiff_pages(
102 a,
103 b,
104 threshold=None,
105 verbosity=None,
106 dpi=None,
107 tempdir=None,
108 time_to_inspect=0,
109 num_threads=None,
110 max_report_pagenos=None,
111):
112 """
113 Find visual differences between two PDFs; return the page numbers with
114 significant differences.
115
116 When the number of pages is different between the PDFs, then return [-1].
117
118 Keyword arguments:
119
120 tempdir: if not None, then this should be a pathlib.Path for an empty writable
121 directory where we will put temporary files, which help the user understand
122 where differences are and what led to the conclusion on whether the two
123 PDF files are significantly different.
124
125 The layout of this directory is not guaranteed to remain stable across
126 releases of diff_pdf_visually, but it may contain an image for each page of
127 either PDF, and an image for the difference, and a text log.
128
129 time_to_inspect: after computing the diff, wait for this many seconds before
130 removing the temporary directory (if tempdir was not specified) and
131 returning from the function. If tempdir was specified, then we will not
132 remove the directory.
133 """
134
135 assert os.path.isfile(a), "file {} must exist".format(a)
136 assert os.path.isfile(b), "file {} must exist".format(b)
137
138 if threshold is None:
139 threshold = constants.DEFAULT_THRESHOLD
140 if verbosity is None:
141 verbosity = constants.DEFAULT_VERBOSITY
142 if dpi is None:
143 dpi = constants.DEFAULT_DPI
144 if num_threads is None:
145 num_threads = constants.DEFAULT_NUM_THREADS
146 if max_report_pagenos is None:
147 max_report_pagenos = constants.MAX_REPORT_PAGENOS
148
149 if tempdir == None:
150 path_context = tempfile.TemporaryDirectory(prefix="diffpdf-")
151 else:
152 assert isinstance(tempdir, pathlib.Path)
153 assert tempdir.is_dir(), \
154 f"Temporary directory {tempdir} should be an existing directory"
155 assert list(tempdir.glob('*')) == [], \
156 f"temporary directory {tempdir} should be empty at the start"
157 path_context = nullcontext(tempdir)
158

Callers 2

test_examplesFunction · 0.90
pdf_similarFunction · 0.85

Calls 2

nullcontextClass · 0.85
imgdiffFunction · 0.85

Tested by 1

test_examplesFunction · 0.72