Beispiel #1
0
def test_attr_access(resources):
    pdf = Pdf.open(resources / 'graph.pdf')
    assert int(pdf.root.Pages.Count) == 1
Beispiel #2
0
def test_empty_pdf(outdir):
    q = Pdf.new()
    with pytest.raises(IndexError):
        q.pages[0]
    q.save(outdir / 'empty.pdf')
Beispiel #3
0
def pal(resources):
    return Pdf.open(resources / 'pal-1bit-rgb.pdf')
Beispiel #4
0
import split_pdf
from pikepdf import Pdf


if __name__ == '__main__':
    data = {}
    file_path = input("请输入文件路径: ")
    opcode = int(input("清输入操作码: "))
    if opcode == 0:
        # 提取单个页面
        data["number"] = int(input("请输入要获得的页: "))
    if opcode == 1:
        # 提取部分文件
        data["start"] = int(input("请输入起始页: "))
        try:
            data["end"] = int(input("请输入终点页: "))
        except Exception as invalid_input_error:
            data["end"] = None
    stream = Pdf.open(file_path)
    split_pdf.split_pdf(stream, opcode, data)



Beispiel #5
0
def fourpages(resources):
    return Pdf.open(resources / 'fourpages.pdf')
Beispiel #6
0
def graph(resources):
    # Has XMP and docinfo, all standard format XMP
    with Pdf.open(resources / 'graph.pdf') as pdf:
        yield pdf
Beispiel #7
0
def trivial(resources):
    # Has no XMP or docinfo
    with Pdf.open(resources / 'pal-1bit-trivial.pdf') as pdf:
        yield pdf
Beispiel #8
0
 def test_memory(self, resources):
     pdf = (resources / 'pal-1bit-trivial.pdf').read_bytes()
     with pytest.raises(Exception):
         pdf = Pdf.open(pdf)
Beispiel #9
0
def trivial(resources):
    return Pdf.open(resources / 'pal-1bit-trivial.pdf',
                    access_mode=pikepdf.AccessMode.mmap)
Beispiel #10
0
 def test_no_text_stream(self, resources):
     with pytest.raises(TypeError):
         with (resources / 'pal-1bit-trivial.pdf').open('r') as stream:
             Pdf.open(stream)
Beispiel #11
0
 def test_read_not_readable_file(self, outdir):
     writable = (Path(outdir) / 'writeme.pdf').open('wb')
     with pytest.raises(ValueError, match=r'not readable'):
         Pdf.open(writable)
Beispiel #12
0
 def test_stream(self, resources):
     with (resources / 'pal-1bit-trivial.pdf').open('rb') as stream:
         pdf = Pdf.open(stream)
     assert pdf.root.Pages.Count == 1
Beispiel #13
0
def test_overwrite_input(resources, outdir):
    copy(resources / 'sandwich.pdf', outdir / 'sandwich.pdf')
    p = Pdf.open(outdir / 'sandwich.pdf')
    with pytest.raises(ValueError, match=r'overwrite input file'):
        p.save(outdir / 'sandwich.pdf')
Beispiel #14
0
def test_overwrite_with_memory_file(outdir):
    (outdir / 'example.pdf').touch()
    pdf = Pdf.new()
    pdf.save(outdir / 'example.pdf')
Beispiel #15
0
 def test_some_permissions_missing(self, resources):
     pdf = Pdf.open(resources / 'graph-encrypted.pdf', 'owner')
     assert pdf.allow.print_highres == pdf.allow.modify_annotation == False
Beispiel #16
0
def test_non_filename():
    with pytest.raises(TypeError):
        Pdf.open(42.0)
Beispiel #17
0
def vera(resources):
    # Has XMP but no docinfo
    with Pdf.open(resources /
                  'veraPDF test suite 6-2-10-t02-pass-a.pdf') as pdf:
        yield pdf
Beispiel #18
0
def test_file_descriptor(resources):
    with (resources / 'pal-1bit-trivial.pdf').open('rb') as f:
        with pytest.raises(TypeError):
            Pdf.open(f.fileno())
Beispiel #19
0
def sandwich(resources):
    # Has XMP, docinfo, <?adobe-xap-filters esc="CRLF"?>, shorthand attribute XMP
    with Pdf.open(resources / 'sandwich.pdf') as pdf:
        yield pdf
Beispiel #20
0
def test_not_existing_file():
    with pytest.raises(FileNotFoundError):
        Pdf.open('does_not_exist.pdf')
Beispiel #21
0
def invalid_creationdate(resources):
    # Has nuls in docinfo, old PDF
    with Pdf.open(resources / 'invalid_creationdate.pdf') as pdf:
        yield pdf
Beispiel #22
0
def test_empty(outdir):
    target = outdir / 'empty.pdf'
    target.touch()
    with pytest.raises(PdfError):
        Pdf.open(target)
Beispiel #23
0
def graph(resources):
    return Pdf.open(resources / 'graph.pdf')
Beispiel #24
0
 def test_open_pdf_wrong_password(self, resources):
     # The correct passwords are "owner" and "user"
     with pytest.raises(PasswordError):
         Pdf.open(resources / 'graph-encrypted.pdf', password='******')
Beispiel #25
0
def sandwich(resources):
    return Pdf.open(resources / 'sandwich.pdf')
Beispiel #26
0
 def test_open_pdf_password_encoding(self, resources):
     with pytest.raises(PasswordError):
         Pdf.open(resources / 'graph-encrypted.pdf', password=b'\x01\xfe')
Beispiel #27
0
def outlines_doc(resources):
    # Contains an outline with references
    return Pdf.open(resources / 'outlines.pdf')
Beispiel #28
0
 def test_open_pdf_no_password_but_needed(self, resources):
     with pytest.raises(PasswordError):
         Pdf.open(resources / 'graph-encrypted.pdf')
Beispiel #29
0
def inline(resources):
    pdf = Pdf.open(resources / 'image-mono-inline.pdf')
    for operands, _command in parse_content_stream(pdf.pages[0]):
        if operands and isinstance(operands[0], PdfInlineImage):
            return operands[0], pdf
Beispiel #30
0
def test_open_pdf_password(resources):
    pdf = Pdf.open(resources / 'graph-encrypted.pdf', password='******')
    assert pdf.root['/Pages']['/Count'] == 1