Exemplo n.º 1
0
def test_simple_text_stamp(tmp_path):
    outfile: Path = tmp_path / "test-out.pdf"
    text_stamp_file(MINIMAL_PATH,
                    str(outfile),
                    TextStampStyle(stamp_text="Hi, it's\n%(ts)s"),
                    dest_page=0,
                    x=70,
                    y=50)
Exemplo n.º 2
0
def test_simple_text_stamp_missing_params(tmp_path):
    outfile: Path = tmp_path / "test-out.pdf"
    msg = "Stamp text parameter 'foo' is missing"
    with pytest.raises(LayoutError, match=msg):
        text_stamp_file(MINIMAL_PATH,
                        str(outfile),
                        TextStampStyle(stamp_text="%(foo)s missing"),
                        dest_page=0,
                        x=70,
                        y=50)
Exemplo n.º 3
0
def test_stamp_with_undefined_bg_size():
    w = empty_page()

    undef_bg = RawContent(data=STAMP_ART_CONTENT.data)

    long_text = '\n'.join('Test test test test test test test test test '
                          'on an ill-defined background!' for _ in range(60))
    style = TextStampStyle(stamp_text=long_text, background=undef_bg)

    ts = TextStamp(w, style)
    ts.apply(0, x=30, y=120)

    compare_output(w, f'{EXPECTED_OUTPUT_DIR}/undef-bg-size.pdf')
Exemplo n.º 4
0
def test_simple_text_stamp_string_keyed_font():
    gaf = GlyphAccumulatorFactory(FREE_SERIF, font_size=10)

    w = empty_page()
    style = TextStampStyle(
        stamp_text=("Hi, this is a string-keyed font test.\n"
                    "This should have a ligature: difficult"),
        text_box_style=TextBoxStyle(font=gaf),
    )

    ts = TextStamp(w, style, box=layout.BoxConstraints(200, 50))
    ts.apply(dest_page=0, x=70, y=50)

    compare_output(w, f'{EXPECTED_OUTPUT_DIR}/freeserif-test.pdf')
Exemplo n.º 5
0
def test_stamp_with_scaled_bitmap_bg():
    w = empty_page()

    text = '\n'.join('Test test test test on a bitmap background!'
                     for _ in range(3))
    style = TextStampStyle(
        stamp_text=text,
        background=PdfImage('pyhanko_tests/data/img/stamp-indexed.png'),
    )

    ts = TextStamp(w, style, box=layout.BoxConstraints(400, 100))
    ts.apply(0, x=30, y=600)

    compare_output(w, f'{EXPECTED_OUTPUT_DIR}/scaled-bitmap-bg.pdf')
Exemplo n.º 6
0
def test_stamp_with_unscaled_bitmap_bg():
    w = empty_page()

    long_text = '\n'.join('Test test test test test test test test test '
                          'on a bitmap background!' for _ in range(60))
    style = TextStampStyle(
        stamp_text=long_text,
        background=PdfImage('pyhanko_tests/data/img/stamp-indexed.png'),
    )

    ts = TextStamp(w, style)
    ts.apply(0, x=30, y=120)

    compare_output(w, f'{EXPECTED_OUTPUT_DIR}/bitmap-bg.pdf')
Exemplo n.º 7
0
def test_stamp_with_scaled_pdf_bg():
    w = empty_page()

    text = '\n'.join('Test test test test on a PDF background!'
                     for _ in range(3))
    style = TextStampStyle(
        stamp_text=text,
        background=ImportedPdfPage(
            'pyhanko_tests/data/pdf/pdf-background-test.pdf'),
    )

    ts = TextStamp(w, style, box=layout.BoxConstraints(200, 50))
    ts.apply(0, x=30, y=600)

    compare_output(w, f'{EXPECTED_OUTPUT_DIR}/stamp-on-pdf-bg.pdf')
Exemplo n.º 8
0
def _arabic_text_page(stream_xrefs):
    w = empty_page(stream_xrefs=stream_xrefs)
    style = TextStampStyle(
        stamp_text='اَلْفُصْحَىٰ',
        text_box_style=TextBoxStyle(
            font=GlyphAccumulatorFactory(NOTO_SANS_ARABIC), ),
        inner_content_layout=layout.SimpleBoxLayoutRule(
            x_align=layout.AxisAlignment.ALIGN_MID,
            y_align=layout.AxisAlignment.ALIGN_MID,
            inner_content_scaling=layout.InnerScaling.STRETCH_TO_FIT,
            margins=layout.Margins.uniform(5)))
    ts = TextStamp(writer=w,
                   style=style,
                   box=layout.BoxConstraints(width=300, height=200))
    ts.apply(0, x=10, y=60)
    return w
Exemplo n.º 9
0
"""
Default message digest algorithm used when computing digests for use in
signatures.
"""

DEFAULT_SIGNER_KEY_USAGE = {"non_repudiation"}
"""
Default key usage bits required for the signer's certificate.
"""

SIG_DETAILS_DEFAULT_TEMPLATE = ('Digitally signed by %(signer)s.\n'
                                'Timestamp: %(ts)s.')
"""
Default template string for signature appearances.
"""

DEFAULT_SIGNING_STAMP_STYLE = TextStampStyle(
    stamp_text=SIG_DETAILS_DEFAULT_TEMPLATE, background=STAMP_ART_CONTENT)
"""
Default stamp style used for visible signatures.
"""

ESIC_EXTENSION_1 = DeveloperExtension(
    prefix_name=generic.pdf_name('/ESIC'),
    base_version=generic.pdf_name('/1.7'),
    extension_level=1,
    compare_by_level=True,
    multivalued=DevExtensionMultivalued.NEVER)
"""
ESIC extension for PDF 1.7. Used to declare usage of PAdES structures.
"""