示例#1
0
def test_attr_access(resources):
    pdf = Pdf.open(resources / 'graph.pdf')
    assert int(pdf.root.Pages.Count) == 1
示例#2
0
def test_empty_pdf(outdir):
    q = Pdf.new()
    with pytest.raises(IndexError):
        q.pages[0]
    q.save(outdir / 'empty.pdf')
示例#3
0
def pal(resources):
    return Pdf.open(resources / 'pal-1bit-rgb.pdf')
示例#4
0
文件: main.py 项目: boxness/mytoolkit
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)



示例#5
0
def fourpages(resources):
    return Pdf.open(resources / 'fourpages.pdf')
示例#6
0
def graph(resources):
    # Has XMP and docinfo, all standard format XMP
    with Pdf.open(resources / 'graph.pdf') as pdf:
        yield pdf
示例#7
0
def trivial(resources):
    # Has no XMP or docinfo
    with Pdf.open(resources / 'pal-1bit-trivial.pdf') as pdf:
        yield pdf
示例#8
0
 def test_memory(self, resources):
     pdf = (resources / 'pal-1bit-trivial.pdf').read_bytes()
     with pytest.raises(Exception):
         pdf = Pdf.open(pdf)
示例#9
0
def trivial(resources):
    return Pdf.open(resources / 'pal-1bit-trivial.pdf',
                    access_mode=pikepdf.AccessMode.mmap)
示例#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)
示例#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)
示例#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
示例#13
0
文件: test_io.py 项目: xjqx05/pikepdf
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')
示例#14
0
文件: test_io.py 项目: xjqx05/pikepdf
def test_overwrite_with_memory_file(outdir):
    (outdir / 'example.pdf').touch()
    pdf = Pdf.new()
    pdf.save(outdir / 'example.pdf')
示例#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
示例#16
0
def test_non_filename():
    with pytest.raises(TypeError):
        Pdf.open(42.0)
示例#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
示例#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())
示例#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
示例#20
0
def test_not_existing_file():
    with pytest.raises(FileNotFoundError):
        Pdf.open('does_not_exist.pdf')
示例#21
0
def invalid_creationdate(resources):
    # Has nuls in docinfo, old PDF
    with Pdf.open(resources / 'invalid_creationdate.pdf') as pdf:
        yield pdf
示例#22
0
def test_empty(outdir):
    target = outdir / 'empty.pdf'
    target.touch()
    with pytest.raises(PdfError):
        Pdf.open(target)
示例#23
0
def graph(resources):
    return Pdf.open(resources / 'graph.pdf')
示例#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='******')
示例#25
0
def sandwich(resources):
    return Pdf.open(resources / 'sandwich.pdf')
示例#26
0
 def test_open_pdf_password_encoding(self, resources):
     with pytest.raises(PasswordError):
         Pdf.open(resources / 'graph-encrypted.pdf', password=b'\x01\xfe')
示例#27
0
def outlines_doc(resources):
    # Contains an outline with references
    return Pdf.open(resources / 'outlines.pdf')
示例#28
0
 def test_open_pdf_no_password_but_needed(self, resources):
     with pytest.raises(PasswordError):
         Pdf.open(resources / 'graph-encrypted.pdf')
示例#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
示例#30
0
def test_open_pdf_password(resources):
    pdf = Pdf.open(resources / 'graph-encrypted.pdf', password='******')
    assert pdf.root['/Pages']['/Count'] == 1