PDF-Make

 view release on metacpan or  search on metacpan

examples/builder_enhanced.pl  view on Meta::CPAN

    ->add_field(
        type       => 'text',
        name       => 'full_name',
        label      => 'Full Name',
        w          => 300,
    )
    ->add_field(
        type          => 'text',
        name          => 'email',
        label         => 'Email Address',
        w             => 300,
        default_value => 'user@example.com',
    )
    ->add_field(
        type       => 'text',
        name       => 'comments',
        label      => 'Comments',
        w          => 400,
        h          => 60,
        multiline  => 1,
    )
    ->add_field(
        type       => 'checkbox',
        name       => 'agree_terms',
        label      => 'I agree to the terms and conditions',
    )
    ->add_field(
        type       => 'combo',
        name       => 'country',
        label      => 'Country',
        w          => 200,
        options    => ['United States', 'United Kingdom', 'Canada', 'Australia', 'Germany', 'France'],
    )
    ->add_field(
        type       => 'button',
        name       => 'submit_btn',
        caption    => 'Visit CPAN',
        url        => 'https://metacpan.org',
        w          => 120,
    )
    ->add_field(
        type       => 'button',
        name       => 'reset_btn',
        caption    => 'Reset Form',
        is_reset   => 1,
        w          => 120,
    );

# ══════════════════════════════════════════════════════════════
# Page 7: Color Spaces + Redaction
# ══════════════════════════════════════════════════════════════

$pdf->add_page()
    ->add_h1(text => 'Color & Redaction')
    ->add_h2(text => 'Color Spaces')
    ->add_text(text => 'sRGB color space registered for calibrated color output.')
    ->set_color_space('sRGB')
    ->add_h2(text => 'Redaction')
    ->add_text(text => 'Sensitive information: SSN 123-45-6789')
    ->add_text(text => 'The area above can be marked for redaction. '
                     . 'Call apply_redactions() to burn the overlay permanently.')
    ->mark_redaction(
        page          => 6,
        rect          => [36, 530, 350, 545],
        overlay_color => [0, 0, 0],
        overlay_text  => 'REDACTED',
    );

# ══════════════════════════════════════════════════════════════
# Page 8: Attachments + Watermark
# ══════════════════════════════════════════════════════════════

$pdf->add_page()
    ->add_h1(text => 'Attachments & Watermark')
    ->add_h2(text => 'Embedded Files')
    ->add_text(text => 'This PDF has a CSV file attached. Open the attachment '
                     . 'panel in your PDF viewer to see it.')
    ->attach(
        name        => 'sample_data.csv',
        data        => "Name,Score,Grade\nAlice,95,A\nBob,87,B\nCarol,92,A\n",
        mime        => 'text/csv',
        description => 'Sample grade data',
    )
    ->add_h2(text => 'Watermark')
    ->add_text(text => 'A "DRAFT" watermark has been applied across all pages. '
                     . 'Watermarks support opacity, rotation, color, and '
                     . 'position control.')
    ->add_watermark(text => 'DRAFT', opacity => 0.15, size => 72);

# ══════════════════════════════════════════════════════════════
# Page 9: Text Extraction + Encryption info
# ══════════════════════════════════════════════════════════════

$pdf->add_page()
    ->add_h1(text => 'Advanced Features')
    ->add_h2(text => 'Text Extraction')
    ->add_text(text => 'Builder can extract text from existing PDFs:');

my $extracted = eval { $pdf->extract_text('corpus/hello_world.pdf', 0) } // '(not available)';
$pdf->add_text(text => "  Extracted: \"$extracted\"",
              font => { family => 'Courier', size => 9, colour => '#27ae60' });

$pdf->add_h2(text => 'Encryption')
    ->add_text(text => 'Documents can be encrypted with AES-256, AES-128, '
                     . 'RC4-128, or RC4-40. Set via $b->encrypt(...).')
    ->add_h2(text => 'Digital Signatures')
    ->add_text(text => 'Sign documents with PKCS#12 certificates via '
                     . '$b->sign(pkcs12 => "cert.p12", password => "...").')
    ->add_h2(text => 'Tagged PDF (Accessibility)')
    ->add_text(text => 'Call $b->enable_tagging() to auto-generate structure '
                     . 'tags: headings become /H1-/H6, text becomes /P, '
                     . 'images become /Figure.');

# ══════════════════════════════════════════════════════════════
# Page 10: Annotations, Stamps, Metadata
# ══════════════════════════════════════════════════════════════

$pdf->add_page()
    ->add_h1(text => 'Annotations & Stamps')
    ->add_h2(text => 'Sticky Notes')
    ->add_text(text => 'Click the note icon to the right to see the annotation:')
    ->add_note(
        rect => [500, 660, 520, 680],
        text => 'This is a sticky note annotation added via add_note().',
        icon => 'Comment',
        open => 0,



( run in 0.705 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )