github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jhannah / pdf-textblock

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (4)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

PDF::TextBlock - Easier text blocks while using PDF::API2 — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Oops. I made PAUSE mad, so jumping to 0.04. 
jhannah (author)
Wed Oct 21 10:09:08 -0700 2009
commit  4875302823b7d7bd0a54bc1ac31cebd101b022d4
tree    04acc51160347ed687741ff025617fe4c0e5e609
parent  8955bd4058f9daefded3556ea9c469be5078edb8
pdf-textblock / t / 20-demo.t t/20-demo.t
100644 123 lines (98 sloc) 3.606 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use Test::More tests => 9;
 
# Reproduction of http://rick.measham.id.au/pdf-api2/
# Using PDF::TextBlock this time
 
use strict;
use warnings;
use PDF::API2;
use PDF::TextBlock;
use PDF::TextBlock::Font;
 
use constant mm => 25.4 / 72;
use constant in => 1 / 72;
use constant pt => 1;
 
my $picture = "t/camel.jpg";
 
ok(my $pdf = PDF::API2->new( -file => "20-demo.pdf" ), "PDF::API2->new()");
my $page = $pdf->page;
$page->mediabox( 105/mm, 148/mm );
#$page->bleedbox( 5/mm, 5/mm, 100/mm, 143/mm);
$page->cropbox( 7.5/mm, 7.5/mm, 97.5/mm, 140.5/mm );
#$page->artbox ( 10/mm, 10/mm, 95/mm, 138/mm);
 
my $blue_box = $page->gfx;
$blue_box->fillcolor('darkblue');
$blue_box->rect( 5/mm, 125/mm, 95/mm, 18/mm );
$blue_box->fill;
 
my $red_line = $page->gfx;
$red_line->strokecolor('red');
$red_line->move( 5/mm, 125/mm );
$red_line->line( 100/mm, 125/mm );
$red_line->stroke;
 
 
# headline_text
ok(my $tb = PDF::TextBlock->new({
   pdf => $pdf,
   page => $page,
   text => 'Using PDF::TextBlock',
   fonts => {
      default => PDF::TextBlock::Font->new({
         pdf => $pdf,
         fillcolor => 'white',
         size => 18/pt,
      }),
   },
   x => 95/mm,
   y => 131/mm,
   align => 'text_right',
}), "new()");
ok($tb->apply(), "apply()");
 
 
my $background = $page->gfx;
$background->strokecolor('lightgrey');
$background->circle( 20/mm, 45/mm, 45/mm );
$background->circle( 18/mm, 48/mm, 43/mm );
$background->circle( 19/mm, 40/mm, 46/mm );
$background->stroke;
 
 
# left_column_text1
ok($tb = PDF::TextBlock->new({
   pdf => $pdf,
   page => $page,
   fonts => {
      default => PDF::TextBlock::Font->new({
         pdf => $pdf,
         size => 6/pt,
      }),
   },
   x => 10/mm,
   y => 119/mm,
   w => 41.5/mm,
   h => 110/mm - 7/pt,
   lead => 7/pt,
}), "new() left_column_text1");
my ($endw, $ypos);
ok(($endw, $ypos) = $tb->apply(), "apply() left_column_text1");
 
 
# left_column_text2 - blue bold line
$tb->text("This .pdf generated by t/20-demo.t.\nWe hope you enjoy it!");
$tb->fonts->{default}->fillcolor('darkblue');
$tb->y($ypos - 7/pt); # Dynamic from end of last TextBlock
$tb->h(110/mm - ( 119/mm - $ypos )); # Dynamic from end of last TextBlock
$tb->align('center');
ok(($endw, $ypos) = $tb->apply(), "apply() left_column_text2");
 
 
# left_column_text3
$tb->text($tb->garbledy_gook);
$tb->fonts->{default}->fillcolor(undef);
$tb->y($ypos - 7/pt); # Dynamic from end of last TextBlock
$tb->h(110/mm - ( 119/mm - $ypos )); # Dynamic from end of last TextBlock
$tb->align('justify');
ok(($endw, $ypos) = $tb->apply(), "apply() left_column_text3");
 
 
my $photo = $page->gfx;
die("Unable to find image file: $!") unless -e $picture;
my $photo_file = $pdf->image_jpeg($picture);
$photo->image( $photo_file, 54 / mm, 66 / mm, 41 / mm, 55 / mm );
 
 
# right_column_text
$tb->text($tb->garbledy_gook);
$tb->fonts->{default}->fillcolor(undef);
$tb->x(54/mm);
$tb->y(62/mm);
$tb->h(54/mm);
$tb->align('justify');
ok(($endw, $ypos) = $tb->apply(), "apply() right_column_text");
 
 
$pdf->save; # Doesn't return true, even when it succeeds. -sigh-
$pdf->end; # Doesn't return true, even when it succeeds. -sigh-
ok(-r "20-demo.pdf", "20-demo.pdf created");
 
diag( "Testing PDF::TextBlock $PDF::TextBlock::VERSION, Perl $], $^X" );
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server