예제 #1
0
def test_issue604(strict):
    """Test with invalid destinations"""  # todo
    with open(os.path.join(RESOURCE_ROOT, "issue-604.pdf"), "rb") as f:
        pdf = None
        bookmarks = None
        if strict:
            pdf = PdfReader(f, strict=strict)
            with pytest.raises(PdfReadError) as exc, pytest.warns(
                    PdfReadWarning):
                bookmarks = pdf._get_outlines()
            if "Unknown Destination" not in exc.value.args[0]:
                raise Exception("Expected exception not raised")
            return  # bookmarks not correct
        else:
            pdf = PdfReader(f, strict=strict)
            with pytest.warns(PdfReadWarning):
                bookmarks = pdf._get_outlines()

        def get_dest_pages(x):
            if isinstance(x, list):
                r = [get_dest_pages(y) for y in x]
                return r
            else:
                return pdf.get_destination_page_number(x) + 1

        out = []
        for (
                b
        ) in bookmarks:  # b can be destination or a list:preferred to just print them
            out.append(get_dest_pages(b))
예제 #2
0
def test_get_destination_page_number():
    src = os.path.join(RESOURCE_ROOT, "pdflatex-outline.pdf")
    reader = PdfReader(src)
    outlines = reader._get_outlines()
    for outline in outlines:
        if not isinstance(outline, list):
            reader.get_destination_page_number(outline)
예제 #3
0
def test_get_outlines(src, outline_elements):
    reader = PdfReader(src)
    outlines = reader._get_outlines()
    assert len(outlines) == outline_elements