예제 #1
0
def test_text(pdf_page):
    text = pdf_page.text()
    if version() < (0, 46, 0):
        expected = "Page "
    elif version() < (0, 88, 0):
        expected = "Page 1"
    else:
        expected = "Page 1\n\x0c"
    assert text == expected
예제 #2
0
def test_load_with_file(data_path):
    with (data_path / "document.pdf").open("rb") as f:
        pdf_document = document.load(f, "owner", "user")
    if version() < (0, 46, 0):
        assert pdf_document.author == "Charles"
    else:
        assert pdf_document.author == "Charles Brunet"
예제 #3
0
def test_load_with_filename(data_path):
    pdf_document = document.load(str(data_path / "document.pdf"), "owner",
                                 "user")
    if version() < (0, 46, 0):
        assert pdf_document.author == "Charles"
    else:
        assert pdf_document.author == "Charles Brunet"
예제 #4
0
def test_load_with_bytes(data_path):
    data = (data_path / "document.pdf").read_bytes()
    pdf_document = document.load(data, "owner", "user")
    if version() < (0, 46, 0):
        assert pdf_document.author == "Charles"
    else:
        assert pdf_document.author == "Charles Brunet"
예제 #5
0
def test_info_date(pdf_document):
    date = pdf_document.info_date("CreationDate")
    if version() < (0, 46, 0):
        assert date.astimezone(timezone.utc) == datetime(
            2020, 3, 25, 21, 19, 50, tzinfo=timezone.utc
        )
    else:
        assert date.astimezone(timezone.utc) == datetime(
            2020, 3, 26, 1, 19, 50, tzinfo=timezone.utc
        )
예제 #6
0
def test_text_list(pdf_page):
    text_list = pdf_page.text_list()
    assert len(text_list) == 2

    text_box = text_list[0]
    assert text_box.text == "Page"
    assert pytest.approx(text_box.bbox.as_tuple(), abs=0.1) == (56.8, 57.2, 80.1, 70.5)
    if version() >= (0, 68, 0):
        assert text_box.rotation == 0
    assert pytest.approx(text_box.char_bbox(0).as_tuple(), abs=0.1) == (
        56.8,
        57.2,
        63.5,
        70.5,
    )
    assert text_box.has_space_after is True
예제 #7
0
def test_info_key(pdf_document):
    info = pdf_document.info_key("Author")
    if version() < (0, 46, 0):
        assert info == "Charles"
    else:
        assert info == "Charles Brunet"
예제 #8
0
def test_get_producer(pdf_document):
    if version() < (0, 46, 0):
        assert pdf_document.producer == "LibreOf"
    else:
        assert pdf_document.producer == "LibreOffice 6.4"
예제 #9
0
def test_get_creator(pdf_document):
    if version() < (0, 46, 0):
        assert pdf_document.creator == "Wri"
    else:
        assert pdf_document.creator == "Writer"
예제 #10
0
def test_get_author(pdf_document):
    if version() < (0, 46, 0):
        assert pdf_document.author == "Charles"
    else:
        assert pdf_document.author == "Charles Brunet"
예제 #11
0
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import pytest

from poppler.page import Page
from poppler.rectangle import Rectangle
from poppler import version
from poppler import CaseSensitivity


def test_page_duration(pdf_page):
    assert pdf_page.duration == -1.0


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_page_label(pdf_page):
    assert pdf_page.label == "1"


def test_page_orientation(pdf_page):
    assert pdf_page.orientation == Page.Orientation.portrait


def test_page_rect(pdf_page):
    r = pdf_page.page_rect()
    assert r.as_tuple() == (0.0, 0.0, 612.0, 792.0)


@pytest.mark.parametrize(
    "box",
예제 #12
0
def test_text(pdf_page):
    text = pdf_page.text()
    expected = "Page 1" if version() < (0, 88, 0) else "Page 1\n\x0c"
    assert text == expected
예제 #13
0
        Page.PageBox.trim_box,
        Page.PageBox.art_box,
    ],
)
def test_page_rect_box(pdf_page, box):
    r = pdf_page.page_rect(box)
    assert r.as_tuple() == (0.0, 0.0, 612.0, 792.0)


def test_text(pdf_page):
    text = pdf_page.text()
    expected = "Page 1" if version() < (0, 88, 0) else "Page 1\n\x0c"
    assert text == expected


@pytest.mark.skipif(version() < (0, 63, 0),
                    reason="Requires at least Poppler 0.63.0")
def test_text_list(pdf_page):
    text_list = pdf_page.text_list()
    assert len(text_list) == 2

    text_box = text_list[0]
    assert text_box.text == "Page"
    assert pytest.approx(text_box.bbox.as_tuple(),
                         abs=0.1) == (56.8, 57.2, 80.1, 70.5)
    if version() >= (0, 68, 0):
        assert text_box.rotation == 0
    assert pytest.approx(text_box.char_bbox(0).as_tuple(), abs=0.1) == (
        56.8,
        57.2,
        63.5,
예제 #14
0
def test_version_string():
    assert tuple(map(int, version_string().split("."))) == version()
예제 #15
0
    else:
        assert pdf_document.author == "Charles Brunet"


def test_load_with_file_not_bytes(data_path):
    with (data_path / "document.pdf").open("r") as f:
        with pytest.raises(TypeError):
            document.load(f, "owner", "user")


def test_load_with_invalid_type():
    with pytest.raises(TypeError):
        document.load(42)


@pytest.mark.skipif(version() < (0, 46, 0),
                    reason="Requires at least Poppler 0.46.0")
def test_save(pdf_document, tmp_path):
    copy_document = tmp_path / "copy.pdf"
    pdf_document.author = "Valérie Tremblay"
    assert pdf_document.save(copy_document)

    pdf_copy = document.load(copy_document, "owner", "user")
    assert pdf_copy.author == "Valérie Tremblay"


@pytest.mark.skipif(version() < (0, 46, 0),
                    reason="Requires at least Poppler 0.46.0")
def test_save_a_copy(pdf_document, tmp_path):
    copy_document = tmp_path / "copy.pdf"
    pdf_document.author = "Valérie Tremblay"
예제 #16
0
def test_infos(pdf_document):
    infos = pdf_document.infos()
    if version() < (0, 46, 0):
        assert infos['Author'] == 'Charles'
    else:
        assert infos["Author"] == "Charles Brunet"
예제 #17
0
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import pytest

from poppler.pagerenderer import PageRenderer, RenderHint
from poppler.image import Image
from poppler import version

if version() >= (0, 65, 0):
    from poppler.pagerenderer import LineMode


def test_can_render():
    assert PageRenderer.can_render() is True


@pytest.mark.skipif(version() < (0, 65, 0),
                    reason="Requires at least Poppler 0.65.0")
def test_image_format():
    renderer = PageRenderer()

    assert renderer.image_format == Image.Format.argb32

예제 #18
0
    with (data_path / "document.pdf").open("r") as f:
        with pytest.raises(TypeError):
            document.load(f, "owner", "user")


def test_load_with_invalid_type():
    with pytest.raises(TypeError):
        document.load(42)


def test_load_not_a_pdf_document(data_path):
    with pytest.raises(ValueError):
        _ = document.load(str(data_path / "sample.tex"))


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_save(pdf_document, tmp_path):
    copy_document = tmp_path / "copy.pdf"
    pdf_document.author = "Valérie Tremblay"
    assert pdf_document.save(copy_document)

    pdf_copy = document.load(copy_document, "owner", "user")
    assert pdf_copy.author == "Valérie Tremblay"


@pytest.mark.skipif(version() < (0, 46, 0), reason="Requires at least Poppler 0.46.0")
def test_save_a_copy(pdf_document, tmp_path):
    copy_document = tmp_path / "copy.pdf"
    pdf_document.author = "Valérie Tremblay"
    assert pdf_document.save_a_copy(copy_document)
예제 #19
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import pytest

from poppler import version

if version() >= (0, 74, 0):
    from poppler import DestinationType

pytestmark = pytest.mark.skipif(
    version() < (0, 74, 0), reason="Requires at least Poppler 0.74.0"
)


def test_destination_map_keys(sample_document):
    destinations = sample_document.create_destination_map()

    assert "Doc-Start" in destinations
    assert "Navigation1" in destinations
    assert "Outline0.1" in destinations
    assert "page.1" in destinations
예제 #20
0
def test_version_string():
    assert version_string() == ".".join(map(str, version()))