Skip to content

Commit

Permalink
README - add XObject Form example
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Aug 10, 2017
1 parent a2c5009 commit 5881e40
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
55 changes: 48 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ Deletes a page, by page-number

# SECTION II: Graphics Methods (inherited from PDF::Lite)

## Graphics Introduction
## Introduction to Graphics

Graphics form the basis of PDF rendering and display. This includes text, images,
graphics, colors and painting.
Expand All @@ -323,10 +323,10 @@ my $gfx = $page.gfx;
dd $gfx.content-dump; # dump existing graphics operations
# add some more text to the page
$gfx.font = .core-font; :family<Courier>;
$gfx.TextMove = [10, 30];
$gfx.font = $gfx.core-font: :family<Courier>;
$gfx.BeginText;
$gfx.say("Demo added text")l
$gfx.TextMove = [10, 30];
$gfx.say("Demo added text");
$gfx.EndText;
```
Expand Down Expand Up @@ -386,7 +386,7 @@ Synopsis: `$gfx.text-transform: :$matrix, :translate[$x,$y], :rotate($rad), :sca

Applies a text transform, such as translation, rotation, scaling, etc.

$gfx.transform: :translate[110, 10];
$gfx.text-transform: :translate[110, 10];

- Text transforms are applied after any [Graphics Transform](#transform).

Expand Down Expand Up @@ -421,7 +421,7 @@ Synopsis: `$gfx.transform: :$matrix, :translate[$x,$y], :rotate($rad), :scale[$s

Applies a graphics transform, such as translation, rotation, scaling, etc.

$gfx.transform: :translate[110, 10];
$gfx.transform: :rotate(pi/4), :scale(2);

Unlike [Text Transforms](#text-transform), Graphics Transforms accumulate; and are applied in addition to any existing transforms.

Expand Down Expand Up @@ -461,10 +461,51 @@ Displays an image or form.

A Form is a graphical sub-element. Its usage is the same as an image.

### xobject-form

This graphical method is used to create a new, empty form object:
```
use v6;
use PDF::API6;
my PDF::API6 $pdf .= new;
my $page = $pdf.add-page;
$page.MediaBox = [0, 0, 275, 100];
# create a new XObject form of size 120 x 50
my @BBox = [0, 0, 120, 50];
my $form = $page.xobject-form: :@BBox;
$form.graphics: {
# color the entire form
.FillColor = :DeviceRGB[.9, .8, .8];
.Rectangle: |@BBox;
.paint: :fill, :stroke;
}
$form.text: {
# some sample text
.font = .core-font('Helvetica');
.TextMove = 10, 10;
.say: "Sample form";
}
# display the form a couple of times
$page.graphics: {
.transform: :translate(10, 10);
.do($form);
.transform: :translate(130, 0), :rotate(.1);
.do($form);
}
$pdf.save-as: "examples/sample-form.pdf";
```

![example.pdf](examples/.previews/sample-form-001.png)


## Patterns

A Pattern is another graphical sub-element. Its usage is the same as a color.
A Pattern is another graphical sub-element. Its construction is similar to a form; its usage is the same as a color.

Patterns are typically used to achieve advanced tiling or shading effects.

Expand Down
Binary file added examples/.previews/sample-form-001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions lib/PDF/API6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ class PDF::API6:ver<0.0.1>
if !$update and self.reader {
with $.catalog<AcroForm> {
# guard against signature invalidation
my $sig-flags = .<SigFlags>;
constant AppendOnly = 2;
my $sig-flags = .<SigFlags>;
if $sig-flags && $sig-flags.flag-is-set: AppendOnly {
with $update {
# callee has specified :!update
die "This PDF contains digital signatures that will be invalidated with .save-as :!update"
}
else {
# set :update to preserve digital signatures
$update = True;
# save in :update mode to preserve digital signatures
$_ = True;
}
}
}
Expand Down
Binary file added preferences.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion t/00-readme.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use Test;
plan 11;
plan 3;

my $read-me = "README.md".IO.slurp;

Expand Down
Binary file added t/basic.pdf
Binary file not shown.

0 comments on commit 5881e40

Please sign in to comment.