1PDF::Haru(3) User Contributed Perl Documentation PDF::Haru(3)
2
3
4
6 PDF::Haru - Perl interface to Haru Free PDF Library. Haru is a free,
7 cross platform, open-sourced software library for generating PDF.
8
10 use PDF::Haru;
11
12 # create new document
13 my $pdf = PDF::Haru::New();
14
15 # add page
16 my $page = $pdf->AddPage();
17
18 # set page size and orientation
19 $page->SetSize(HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
20
21 my $font = $pdf->GetFont("Helvetica", "StandardEncoding");
22 $page->BeginText();
23 $page->SetFontAndSize($font, 20);
24 $page->TextOut(40, 781, "text");
25 $page->EndText();
26
27 $page->Rectangle (30, 30, $page->GetWidth() - 60, $page->GetHeight() - 60);
28 $page->Stroke();
29
30 # save the document to a file
31 $pdf->SaveToFile("filename.pdf");
32
33 # cleanup
34 $pdf->Free();
35
37 my $pdf = PDF::Haru::New()
38 Create an instance of a document object and initialize it.
39
40 $pdf->Free()
41 Revokes a document object and all resources.
42
43 $pdf->NewDoc()
44 Creates new document. If document object already has a document, the
45 current document is revoked.
46
47 $pdf->FreeDoc()
48 Revokes the current document. Keeps loaded resource (such as fonts and
49 encodings) and these resources are recycled when new document required
50 these resources.
51
52 $pdf->FreeDocAll()
53 Revokes the current document and all resources.
54
55 $pdf->SaveToFile("filename.pdf")
56 Saves the current document to a file.
57
58 $pdf->SaveAsString()
59 Returns PDF document as string.
60
61 $pdf->SetPagesConfiguration($page_per_pages)
62 In the default setting, a PDF::Haru object has one "Pages" object as
63 root of pages. All "Page" objects are created as a kid of the "Pages"
64 object. Since a "Pages" object can own only 8191 kids objects, the
65 maximum number of pages are 8191 page.
66
67 Additionally, the state that there are a lot of "Page" object under
68 one "Pages" object is not good, because it causes performance
69 degradation of a viewer application.
70
71 An application can change the setting of a pages tree by invoking
72 SetPagesConfiguration(). If $page_per_pages parameter is set to more
73 than zero, a two-tier pages tree is created. A root "Pages" object can
74 own 8191 "Pages" object, and each lower "Pages" object can own
75 $page_per_pages "Page" objects. As a result, the maximum number of
76 pages becomes 8191 * $page_per_pages page.
77
78 An application cannot invoke SetPageConfiguration() after a page is
79 added to document.
80
81 $pdf->SetPageLayout(layout)
82 Sets how the page should be displayed. If this attribute is not set,
83 the setting of a viewer application is used.
84
85 layout is one of following constants
86
87 HPDF_PAGE_LAYOUT_SINGLE
88 Only one page is displayed.
89
90 HPDF_PAGE_LAYOUT_ONE_COLUMN
91 Display the pages in one column.
92
93 HPDF_PAGE_LAYOUT_TWO_COLUMN_LEFT
94 Display the pages in two column. The page of the odd number is
95 displayed left.
96
97 HPDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT
98 Display the pages in two column. The page of the odd number is
99 displayed right.
100
101 Example:
102 $pdf->SetPageLayout(HPDF_PAGE_LAYOUT_ONE_COLUMN)
103
104 $pdf->GetPageLayout()
105 Returns the current setting for page layout.
106
107 $pdf->SetPageMode(mode)
108 Sets how the document should be displayed.
109
110 mode is one of following constants
111
112 HPDF_PAGE_MODE_USE_NONE
113 Display the document with neither outline nor thumbnail.
114
115 HPDF_PAGE_MODE_USE_OUTLINE
116 Display the document with outline pain.
117
118 HPDF_PAGE_MODE_USE_THUMBS
119 Display the document with thumbnail pain.
120
121 HPDF_PAGE_MODE_FULL_SCREEN
122 Display the document with full screen mode.
123
124 Example:
125 $pdf->SetPageMode(HPDF_PAGE_MODE_FULL_SCREEN)
126
127 $pdf->GetPageLayout()
128 Returns the current setting for page mode.
129
130 $pdf->SetOpenAction($destination)
131 Set the first page appears when a document is opened. $destination is a
132 destination object created by $page->CreateDestination() function.
133
134 my $page = $pdf->GetCurrentPage()
135 Returns the handle of current page object.
136
137 my $page = $pdf->AddPage()
138 Creates a new page and adds it after the last page of a document.
139
140 my $page = $pdf->InsertPage($target)
141 Creates a new page and inserts it just before the specified page.
142
143 $pdf->LoadType1FontFromFile($afmfilename, $pfmfilename)
144 Loads a type1 font from an external file and register it to a document
145 object. Returns the name of a font.
146
147 $afmfilename
148 A path of an AFM file.
149
150 $pfmfilename
151 A path of a PFA/PFB file. If it is undef, the gryph data of font
152 file is not embedded to a PDF file.
153
154 $pdf->LoadTTFontFromFile ($file_name, embedding)
155 Loads a TrueType font from an external file and register it to a
156 document object. Returns the name of a font.
157
158 $file_name
159 A path of a TrueType font file (.ttf).
160
161 embedding
162 If this parameter is set to HPDF_TRUE, the glyph data of the font
163 is embedded, otherwise only the matrix data is included in PDF
164 file.
165
166 $pdf->LoadTTFontFromFile2 ($file_name, $index, embedding)
167 Loads a TrueType font from an TrueType collection file and register it
168 to a document object. Returns the name of a font.
169
170 $file_name
171 A path of a TrueType font collection file (.ttc).
172
173 $index
174 The index of font that wants to be loaded.
175
176 embedding
177 If this parameter is set to HPDF_TRUE, the glyph data of the font
178 is embedded, otherwise only the matrix data is included in PDF
179 file.
180
181 $pdf->AddPageLabel($page_num, style, $first_page, $prefix)
182 Adds a page labeling range for the document.
183
184 $page_num
185 The first page that applies this labeling range.
186
187 style
188 The numbering style:
189
190 HPDF_PAGE_NUM_STYLE_DECIMAL
191 Page label is displayed by Arabic numerals.
192
193 HPDF_PAGE_NUM_STYLE_UPPER_ROMAN
194 Page label is displayed by Uppercase roman numerals.
195
196 HPDF_PAGE_NUM_STYLE_LOWER_ROMAN
197 Page label is displayed by Lowercase roman numerals.
198
199 HPDF_PAGE_NUM_STYLE_UPPER_LETTERS
200 Page label is displayed by Uppercase letters (using A to Z).
201
202 HPDF_PAGE_NUM_STYLE_LOWER_LETTERS
203 Page label is displayed by Lowercase letters (using a to z).
204
205 $first_page
206 The first page number in this range.
207
208 $prefix
209 The prefix for the page label.
210
211 my $font = $pdf->GetFont($font_name, $encoding_name)
212 Gets the handle of a corresponding font object by specified name and
213 encoding.
214
215 $pdf->UseJPFonts()
216 Enables Japanese fonts. After UseJPFonts() is involed, an application
217 can use the following Japanese fonts.
218
219 * MS-Mincyo
220 * MS-Mincyo,Bold
221 * MS-Mincyo,Italic
222 * MS-Mincyo,BoldItalic
223 * MS-Gothic
224 * MS-Gothic,Bold
225 * MS-Gothic,Italic
226 * MS-Gothic,BoldItalic
227 * MS-PMincyo
228 * MS-PMincyo,Bold
229 * MS-PMincyo,Italic
230 * MS-PMincyo,BoldItalic
231 * MS-PGothic
232 * MS-PGothic,Bold
233 * MS-PGothic,Italic
234 * MS-PGothic,BoldItalic
235
236 $pdf->UseKRFonts()
237 Enables Korean fonts. After UseKRFonts() is involed, an application can
238 use the following Korean fonts.
239
240 * DotumChe
241 * DotumChe,Bold
242 * DotumChe,Italic
243 * DotumChe,BoldItalic
244 * Dotum
245 * Dotum,Bold
246 * Dotum,Italic
247 * Dotum,BoldItalic
248 * BatangChe
249 * BatangChe,Bold
250 * BatangChe,Italic
251 * BatangChe,BoldItalic
252 * Batang
253 * Batang,Bold
254 * Batang,Italic
255 * Batang,BoldItalic
256
257 $pdf->UseCNSFonts()
258 Enables simplified Chinese fonts. After UseCNSFonts() is involed, an
259 application can use the following simplified Chinese fonts.
260
261 * SimSun
262 * SimSun,Bold
263 * SimSun,Italic
264 * SimSun,BoldItalic
265 * SimHei
266 * SimHei,Bold
267 * SimHei,Italic
268 * SimHei,BoldItalic
269
270 $pdf->UseCNTFonts()
271 Enables traditional Chinese fonts. After UseCNTFonts() is involed, an
272 application can use the following traditional Chinese fonts.
273
274 * MingLiU
275 * MingLiU,Bold
276 * MingLiU,Italic
277 * MingLiU,BoldItalic
278
279 my $encoder = $pdf->GetEncoder($encoding_name)
280 Gets the handle of a corresponding encoder object by specified encoding
281 name.
282
283 my $encoder = $pdf->GetCurrentEncoder()
284 Gets the handle of the current encoder of the document object. The
285 current encoder is set by invoking SetCurrentEncoder() and it is used
286 to processing a text when an application invoks Info_SetInfoAttr(). The
287 default value of it is undef.
288
289 $pdf->SetCurrentEncoder($encoding_name)
290 Sets the current encoder for the document.
291
292 $pdf->UseJPEncodings()
293 Enables Japanese encodings. After UseJPEncodings() is involed, an
294 application can use the following Japanese encodings.
295
296 * 90ms-RKSJ-H
297 * 90ms-RKSJ-V
298 * 90msp-RKSJ-H
299 * EUC-H
300 * EUC-V
301
302 $pdf->UseKREncodings()
303 Enables Korean encodings. After UseKREncodings() is involed, an
304 application can use the following Korean encodings.
305
306 * KSC-EUC-H
307 * KSC-EUC-V
308 * KSCms-UHC-H
309 * KSCms-UHC-HW-H
310 * KSCms-UHC-HW-V
311
312 $pdf->UseCNSEncodings()
313 Enables simplified Chinese encodings. After UseCNSEncodings() is
314 involed, an application can use the following simplified Chinese
315 encodings.
316
317 * GB-EUC-H
318 * GB-EUC-V
319 * GBK-EUC-H
320 * GBK-EUC-V
321
322 $pdf->UseCNTEncodings()
323 Enables traditional Chinese encodings. After UseCNTEncodings() is
324 involed, an application can use the following traditional Chinese
325 encodings.
326
327 * GB-EUC-H
328 * GB-EUC-V
329 * GBK-EUC-H
330 * GBK-EUC-V
331
332 my $outline = $pdf->CreateOutline($parent,$title,$encoder)
333 Creates a new outline object.
334
335 $parent
336 The handle of an outline object which comes to the parent of the
337 created outline object. If undef, the outline is created as a root
338 outline.
339
340 $title
341 The caption of the outline object.
342
343 $encoder
344 The handle of an encoding object applied to the title. If undef,
345 PDFDocEncoding is used.
346
347 my $image = $pdf->LoadPngImageFromFile($filename)
348 Loads an external png image file and returns image object.
349
350 my $image = $pdf->LoadPngImageFromFile2($filename)
351 Loads an external png image file and returns image object. Unlike
352 LoadPngImageFromFile(), LoadPngImageFromFile2() does not load whole
353 data immediately. (only size and color properties is loaded). The main
354 data is loaded just before the image object is written to PDF, and the
355 loaded data is deleted immediately.
356
357 my $image = $pdf->LoadJpegImageFromFile($filename)
358 Loads an external Jpeg image file and returns image object.
359
360 $pdf->SetInfoAttr (type, $value)
361 SetInfoAttr() sets the text of the info dictionary. SetInfoAttr() uses
362 the current encoding of the document.
363
364 type
365 The following values are available.
366
367 HPDF_INFO_AUTHOR
368 HPDF_INFO_CREATOR
369 HPDF_INFO_TITLE
370 HPDF_INFO_SUBJECT
371 HPDF_INFO_KEYWORDS
372
373 $value
374 A text to set the infomation.
375
376 $pdf->GetInfoAttr (type)
377 Gets an attribute value from info dictionary.
378
379 type
380 The following values are available.
381
382 HPDF_INFO_CREATION_DATE
383 HPDF_INFO_MOD_DATE
384 HPDF_INFO_AUTHOR
385 HPDF_INFO_CREATOR
386 HPDF_INFO_TITLE
387 HPDF_INFO_SUBJECT
388 HPDF_INFO_KEYWORDS
389
390 $pdf->SetInfoDateAttr(type,$year,$month,$day,$hour,$minutes,$seconds,$ind,$off_hour,$off_minutes)
391 Sets a datetime attribute in the info dictionary.
392
393 type
394 One of the following attributes:
395
396 HPDF_INFO_CREATION_DATE
397 HPDF_INFO_MOD_DATE
398
399 $year,$month,$day,$hour,$minutes,$seconds,$ind,$off_hour,$off_minutes
400 The new value for the attribute.
401
402 $year
403 $month Between 1 and 12.
404 $day Between 1 and 28, 29, 30, or 31. (Depends on the month.)
405 $hour 0 to 23
406 $minutes 0 to 59
407 $seconds 0 to 59
408 $ind Relationship of local time to Universal Time (" ", +, −, or Z).
409 $off_hour If "ind" is not space, 0 to 23 is valid. Otherwise, ignored.
410 $off_minutes If "ind" is not space, 0 to 59 is valid. Otherwise, ignored.
411
412 $pdf->SetPassword ($owner_passwd, $user_passwd)
413 Sets the pasword for the document. If the password is set, contents in
414 the document are encrypted.
415
416 $owner_password
417 The password for the owner of the document. The owner can change
418 the permission of the document. Zero length string and the same
419 value as user password are not allowed.
420
421 $user_password
422 The password for the user of the document. The $user_password is
423 allowed to be set to zero length string.
424
425 $pdf->SetPermission(permission)
426 Set the flags of the permission for the document.
427
428 permission flags specifying which operations are permitted. This
429 parameter is set by logical addition of the following values.
430
431 HPDF_ENABLE_READ
432 user can read the document.
433
434 HPDF_ENABLE_PRINT
435 user can print the document.
436
437 HPDF_ENABLE_EDIT_ALL
438 user can edit the contents of the document other than annotations,
439 form fields.
440
441 HPDF_ENABLE_COPY
442 user can copy the text and the graphics of the document.
443
444 HPDF_ENABLE_EDIT
445 user can add or modify the annotations and form fields of the
446 document.
447
448 Example:
449 $pdf->SetPermission(PDF_ENABLE_READ+PDF_ENABLE_PRINT)
450
451 $pdf->SetEncryptionMode(mode, $key_len)
452 Set the type of encryption. As the side effect, SetEncryptionMode()
453 ups the version of PDF to 1.4 when the mode is set to PDF_ENCRYPT_R3.
454
455 mode
456 The flags specifying which operations are permitted. This parameter
457 is set by logical addition of the following values.
458
459 HPDF_ENCRYPT_R2
460 Use "Revision 2" algorithm. The length of key is automatically
461 set to 5(40bit).
462
463 HPDF_ENCRYPT_R3
464 Use "Revision 3" algorithm. Between 5(40bit) and 16(128bit)
465 can be specified for length of the key.
466
467 $key_len
468 Specify the byte length of an encryption key. This parameter is
469 valid only when "mode" parameter is set to PDF_ENCRYPT_R3. Between
470 5(40bit) and 16(128bit) can be specified for length of the key.
471
472 $pdf->SetCompressionMode(mode)
473 mode flags specifying which type of contents should be compressed.
474
475 HPDF_COMP_NONE
476 All contents are not compressed.
477
478 HPDF_COMP_TEXT
479 Compress the contents stream of the page.
480
481 HPDF_COMP_IMAGE
482 Compress the streams of the image objects.
483
484 HPDF_COMP_METADATA
485 Other stream datas (fonts, cmaps and so on) are compressed.
486
487 HPDF_COMP_ALL
488 All stream datas are compressed. (The same as "PDF_COMP_TEXT +
489 PDF_COMP_IMAGE + PDF_COMP_METADATA")
490
491 Example:
492 $pdf->SetCompressionMode(PDF_COMP_TEXT+PDF_COMP_METADATA)
493
494 $page->SetWidth($value)
495 Changes the width of a page. The valid value is between 3 and 14400.
496
497 $page->SetHeight($value)
498 Changes the height of a page. The valid value is between 3 and 14400.
499
500 $page->SetSize(size, direction)
501 Changes the size and direction of a page to a predefined size.
502
503 size
504 Specify a predefined page-size value. The following values are
505 available.
506
507 HPDF_PAGE_SIZE_LETTER
508 HPDF_PAGE_SIZE_LEGAL
509 HPDF_PAGE_SIZE_A3
510 HPDF_PAGE_SIZE_A4
511 HPDF_PAGE_SIZE_A5
512 HPDF_PAGE_SIZE_B4
513 HPDF_PAGE_SIZE_B5
514 HPDF_PAGE_SIZE_EXECUTIVE
515 HPDF_PAGE_SIZE_US4x6
516 HPDF_PAGE_SIZE_US4x8
517 HPDF_PAGE_SIZE_US5x7
518 HPDF_PAGE_SIZE_COMM10
519
520 direction
521 Specify the direction of the page.
522
523 HPDF_PAGE_PORTRAIT
524 HPDF_PAGE_LANDSCAPE
525
526 $page->SetRotate($angle)
527 Sets rotation angle of the page. Angle must be a multiple of 90
528 Degrees.
529
530 $page->GetWidth()
531 Gets the width of a page.
532
533 $page->GetHeight()
534 Gets the height of a page.
535
536 my $destination = $page->CreateDestination()
537 Creates a new destination object for the page.
538
539 my $annotation =
540 $page->CreateTextAnnot($text,$encoder,$left,$bottom,$right,$top)
541 Creates a new text annotation object for the page.
542
543 $text
544 The text to be displayed.
545
546 $encoder
547 An encoder handle which is used to encode the text. If it is undef,
548 PDFDocEncoding is used.
549
550 $left,$bottom,$right,$top
551 A Rectangle where the annotation is displayed.
552
553 my $annotation = $page->CreateLinkAnnot($dst,$left,$bottom,$right,$top)
554 Creates a new link annotation object for the page.
555
556 $dst
557 A handle of destination object to jump to.
558
559 $left,$bottom,$right,$top
560 Rectangle of clickable area.
561
562 my $annotation = $page->CreateURILinkAnnot($uri,$left,$bottom,$right,$top)
563 Creates a new link annotation object for the page.
564
565 $uri
566 URL of destination to jump to.
567
568 $left,$bottom,$right,$top
569 Rectangle of clickable area.
570
571 $page->TextWidth($text)
572 Gets the width of the text in current fontsize, character spacing and
573 word spacing.
574
575 $page->MeasureText ($text, $width, wordwrap)
576 Calculates the byte length which can be included within the specified
577 width.
578
579 $text
580 The text to get width.
581
582 $width
583 The width of the area to put the text.
584
585 wordwrap
586 When there are three words of "ABCDE", "FGH", and "IJKL", and the
587 substring until "J" can be included within the width, if wordwrap
588 parameter is HPDF_FALSE it returns 12, and if wordwrap parameter is
589 HPDF_TRUE it returns 10 (the end of the previous word).
590
591 $page->GetGMode()
592 Gets the current graphics mode.
593
594 my ($x, $y) = $page->GetCurrentPos()
595 Gets the current position for path painting.
596
597 my ($x, $y) = $page->GetCurrentTextPos()
598 Gets the current position for text showing.
599
600 my $font = $page->GetCurrentFont()
601 Gets the handle of the page's current font.
602
603 $page->GetCurrentFontSize()
604 Gets the size of the page's current font.
605
606 my ($a,$b,$c,$d,$x,$y) = $page->GetTransMatrix()
607 Gets the current transformation matrix of the page.
608
609 $page->GetLineWidth()
610 Gets the current line width of the page.
611
612 $page->GetLineCap()
613 Gets the current line cap style of the page.
614
615 $page->GetLineJoin()
616 Gets the current line join style of the page.
617
618 $page->GetMiterLimit()
619 Gets the current value of the page's miter limit.
620
621 my ($dash_pattern,$phase) = $page->GetDash()
622 Gets the current pattern of the page.
623
624 $page->GetFlat()
625 Gets the current value of the page's flatness.
626
627 $page->GetCharSpace()
628 Gets the the current value of the page's character spacing.
629
630 $page->GetWordSpace()
631 Returns the current value of the page's word spacing.
632
633 $page->GetHorizontalScalling()
634 Returns the current value of the page's horizontal scalling for text
635 showing.
636
637 $page->GetTextLeading()
638 Returns the current value of the page's line spacing.
639
640 $page->GetTextRenderingMode()
641 Returns the current value of the page's text rendering mode.
642
643 $page->GetTextRise()
644 Returns the current value of the page's text rising.
645
646 my ($r, $g, $b) = $page->GetRGBFill()
647 Returns the current value of the page's filling color.
648
649 my ($r, $g, $b) = $page->GetRGBStroke()
650 Returns the current value of the page's stroking color.
651
652 my ($c, $m, $y, $k) = $page->GetCMYKFill()
653 Returns the current value of the page's filling color.
654
655 my ($c, $m, $y, $k) = $page->GetCMYKStroke()
656 Returns the current value of the page's stroking color.
657
658 $page->GetGrayFill()
659 Returns the current value of the page's filling color.
660
661 $page->GetGrayStroke()
662 Returns the current value of the page's stroking color.
663
664 $page->GetStrokingColorSpace()
665 Returns the current value of the page's stroking color space.
666
667 $page->GetFillingColorSpace()
668 Returns the current value of the page's stroking color space.
669
670 $page->GetTextMatrix()
671 Gets the current text transformation matrix of the page.
672
673 $page->GetGStateDepth()
674 Returns the number of the page's graphics state stack.
675
676 $page->SetSlideShow(type,$disp_time,$trans_time)
677 Configures the setting for slide transition of the page.
678
679 type
680 The transition style. The following values are available.
681
682 HPDF_TS_WIPE_RIGHT
683 HPDF_TS_WIPE_UP
684 HPDF_TS_WIPE_LEFT
685 HPDF_TS_WIPE_DOWN
686 HPDF_TS_BARN_DOORS_HORIZONTAL_OUT
687 HPDF_TS_BARN_DOORS_HORIZONTAL_IN
688 HPDF_TS_BARN_DOORS_VERTICAL_OUT
689 HPDF_TS_BARN_DOORS_VERTICAL_IN
690 HPDF_TS_BOX_OUT
691 HPDF_TS_BOX_IN
692 HPDF_TS_BLINDS_HORIZONTAL
693 HPDF_TS_BLINDS_VERTICAL
694 HPDF_TS_DISSOLVE
695 HPDF_TS_GLITTER_RIGHT
696 HPDF_TS_GLITTER_DOWN
697 HPDF_TS_GLITTER_TOP_LEFT_TO_BOTTOM_RIGHT
698 HPDF_TS_REPLACE
699
700 $disp_time
701 The display duration of the page. (in seconds)
702
703 $trans_time
704 The duration of the transition effect. Default value is 1(second).
705
706 $page->Arc($x, $y, $ray, $ang1, $ang2)
707 Appends a circle to the current path.
708
709 $x, $y
710 The center point of the circle.
711
712 $ray
713 The ray of the circle.
714
715 $ang1
716 The angle of the begining of the arc.
717
718 $ang2
719 The angle of the end of the arc. It must be greater than ang1.
720
721 $page->BeginText()
722 Begins a text object and sets the current text position to the point
723 (0, 0).
724
725 $page->Circle($x,$y,$ray)
726 Appends a circle to the current path.
727
728 $x, $y
729 The center point of the circle.
730
731 $ray
732 The ray of the circle.
733
734 $page->Clip()
735 $page->ClosePath()
736 Appends a strait line from the current point to the start point of sub
737 path. The current point is moved to the start point of sub path.
738
739 $page->ClosePathStroke()
740 Closes the current path, then it paints the path.
741
742 $page->ClosePathEofillStroke()
743 Closes the current path, fills the current path using the even-odd
744 rule, then it paints the path.
745
746 $page->ClosePathFillStroke()
747 Closes the current path, fills the current path using the nonzero
748 winding number rule, then it paints the path.
749
750 $page->Concat($a, $b, $c, $d, $x, $y)
751 Concat() concatenates the page's current transformation matrix and
752 specified matrix.
753
754 # save the current graphics states
755 $page->GSave ();
756
757 # concatenate the transformation matrix
758 $page->Concat (0.7, 0.3, -0.4, 0.6, 220, 350);
759
760 # show text on the translated coordinates
761 $page->BeginText ();
762 $page->MoveTextPos (50, 100);
763 $page->ShowText ("Text on the translated coordinates");
764 $page->EndText ();
765
766 # restore the graphics states
767 $page->GRestore ();
768
769 $a, $b, $c, $d, $x, $y
770 The transformation matrix to concatenate.
771
772 $page->CurveTo($x1,$y1,$x2,$y2,$x3,$y3)
773 Appends a Bézier curve to the current path using two spesified points.
774 The point ($x1, $y1) and the point ($x2, $y2) are used as the control
775 points for a Bézier curve and current point is moved to the point ($x3,
776 $y3)
777
778 $page->CurveTo2($x2,$y2,$x3,$y3)
779 Appends a Bézier curve to the current path using two spesified points.
780 The current point and the point ($x2, $y2) are used as the control
781 points for a Bézier curve and current point is moved to the point ($x3,
782 $y3)
783
784 $page->CurveTo3($x1,$y1,$x3,$y3)
785 Appends a Bézier curve to the current path using two spesified points.
786 The point ($x1, $y1) and the point ($x3, $y3) are used as the control
787 points for a Bézier curve and current point is moved to the point ($x3,
788 $y3)
789
790 $page->DrawImage($image,$x,$y,$width,$height)
791 Shows an image in one operation.
792
793 $image
794 The handle of an image object.
795
796 $x, $y
797 The lower-left point of the region where image is displayed.
798
799 $width
800 The width of the region where image is displayed.
801
802 $height
803 The width of the region where image is displayed.
804
805 $page->Ellipse($x, $y, $xray, $yray)
806 Appends an ellipse to the current path.
807
808 $x, $y
809 The center point of the circle.
810
811 $xray, $yray
812 The radius in the x and y direction.
813
814 $page->EndPath()
815 Ends the path object without filling and painting operation.
816
817 $page->EndText()
818 Ends a text object.
819
820 $page->Eoclip()
821 $page->Eofill()
822 Fills the current path using the even-odd rule.
823
824 $page->EofillStroke()
825 Fills the current path using the even-odd rule, then it paints the
826 path.
827
828 $page->Fill()
829 Fills the current path using the nonzero winding number rule.
830
831 $page->FillStroke()
832 Fills the current path using the nonzero winding number rule, then it
833 paints the path.
834
835 $page->GRestore()
836 Restore the graphics state which is saved by GSave().
837
838 $page->GSave()
839 Saves the page's current graphics parameter to the stack. An
840 application can invoke GSave() up to 28 and can restore the saved
841 parameter by invoking GRestore().
842
843 The parameters that are saved by GSave() is as follows.
844
845 * Transformation Matrix
846 * Line Width
847 * Line Cap Style
848 * Line Join Style
849 * Miter Limit
850 * Dash Mode
851 * Flatness
852 * Character Spacing
853 * Word Spacing
854 * Horizontal Scalling
855 * Text Leading
856 * Rendering Mode
857 * Text Rise
858 * Filling Color
859 * Stroking Color
860 * Font
861 * Font Size
862
863 $page->LineTo($x,$y)
864 Appends a path from the current point to the specified point.
865
866 $page->MoveTextPos($x,$y)
867 Moves the current text position to the start of the next line with
868 using specified offset values. If the start position of the current
869 line is (x1, y1), the start of the next line is (x1 + $x, y1 + $y).
870
871 $page->MoveTextPos2($x,$y)
872 Moves the current text position to the start of the next line with
873 using specified offset values, and sets the text-leading to -y. If the
874 start position of the current line is (x1, y1), the start of the next
875 line is (x1 + $x, y1 + $y).
876
877 $page->MoveTo($x,$y)
878 Sets the start point for the path to the point.
879
880 $page->MoveToNextLine()
881 Moves the current text position to the start of the next line. If the
882 start position of the current line is (x1, y1), the start of the next
883 line is (x1, y1 - text leading). NOTE: Since the default value of Text
884 Leading is 0, an application have to invoke SetTextLeading() before
885 MoveToNextLine() to set text leading.
886
887 $page->Rectangle($x,$y,$width,$height)
888 Appends a rectangle to the current path.
889
890 $x,$y
891 The lower-left point of the rectangle.
892
893 $width
894 The width of the rectangle.
895
896 $height
897 The height of the rectangle.
898
899 $page->SetCharSpace($value)
900 Sets the character spacing for text showing. The initial value of
901 character spacing is 0.
902
903 $page->SetCMYKFill($c,$m,$y,$k)
904 Sets the filling color. $c,$m,$y,$k - the level of each color element.
905 They must be between 0 and 1.
906
907 $page->SetCMYKStroke($c,$m,$y,$k)
908 Sets the stroking color. $c,$m,$y,$k - the level of each color element.
909 They must be between 0 and 1.
910
911 $page->SetDash(\@dash_pattern,$phase)
912 Sets the line dash pattern in the page.
913
914 \@dash_pattern
915 Pattern of dashes and gaps used to stroke paths.
916
917 $phase
918 The phase in which the pattern begins (default is 0).
919
920 Example:
921 $page->SetDash([8, 7, 2, 7], 0);
922
923 $page->SetExtGState($ext_gstate)
924 Applys the graphics state to the page.
925
926 $ext_gstate
927 The handle of a extended graphics state object.
928
929 $page->SetGrayFill($gray)
930 Sets the filling color. The value of the gray level between 0 and 1.
931
932 $page->SetGrayStroke($gray)
933 Sets the stroking color. The value of the gray level between 0 and 1.
934
935 $page->SetFontAndSize($font,$size)
936 Sets the type of font and size leading.
937
938 $font
939 The handle of a font object.
940
941 $size
942 The size of a font.
943
944 $page->SetHorizontalScalling($value)
945 Sets the horizontal scalling for text showing. The initial value of
946 horizontal scalling is 100.
947
948 $page->SetLineCap(line_cap)
949 line_cap The style of line-cap:
950
951 PDF_BUTT_END
952 The line is squared off at the endpoint of the path.
953
954 PDF_ROUND_END
955 The end of a line becomes a semicircle whose center is the end
956 point of the path.
957
958 PDF_PROJECTING_SCUARE_END
959 The line continues to the point that exceeds half of the stroke
960 width the end point.
961
962 $page->SetLineJoin(line_join)
963 Sets the line join style in the page. line_join The style of line-
964 join.
965
966 HPDF_MITER_JOIN
967 HPDF_ROUND_JOIN
968 HPDF_BEVEL_JOIN
969
970 $page->SetLineWidth($line_width)
971 Sets the width of the line used to stroke a path.
972
973 $page->SetMiterLimit($miter_limit)
974 $page->SetRGBFill($r, $g, $b)
975 Sets the filling color. $r, $g, $b - the level of each color element.
976 They must be between 0 and 1.
977
978 $page->SetRGBStroke($r, $g, $b)
979 Sets the stroking color. $r, $g, $b - the level of each color element.
980 They must be between 0 and 1.
981
982 $page->SetTextLeading($value)
983 Sets the text leading (line spacing) for text showing. The initial
984 value of leading is 0.
985
986 $page->SetTextMatrix($a,$b,$c,$d,$x,$y)
987 $page->SetTextRenderingMode(mode)
988 Sets the text rendering mode. The initial value of text rendering mode
989 is HPDF_FILL.
990
991 mode one of the following values
992
993 HPDF_FILL
994 HPDF_STROKE
995 HPDF_FILL_THEN_STROKE
996 HPDF_INVISIBLE
997 HPDF_FILL_CLIPPING
998 HPDF_STROKE_CLIPPING
999 HPDF_FILL_STROKE_CLIPPING
1000 HPDF_CLIPPING
1001
1002 $page->SetTextRise($value)
1003 Moves the text position in vertical direction by the amount of value.
1004 Useful for making subscripts or superscripts.
1005
1006 $value
1007 Text rise, in user space units.
1008
1009 $page->SetWordSpace($value)
1010 Sets the word spacing for text showing. The initial value of word
1011 spacing is 0.
1012
1013 $page->ShowText($text)
1014 Prints the text at the current position on the page.
1015
1016 $page->ShowTextNextLine($text)
1017 Moves the current text position to the start of the next line, then
1018 prints the text at the current position on the page.
1019
1020 $page->ShowTextNextLineEx($word_space, $char_space, $text)
1021 Moves the current text position to the start of the next line, then
1022 sets the word spacing, character spacing and prints the text at the
1023 current position on the page.
1024
1025 $page->Stroke()
1026 Paints the current path.
1027
1028 $page->TextOut($xpos, $ypos, $text)
1029 Prints the text on the specified position.
1030
1031 $xpos, $ypos
1032 The point position where the text is displayed.
1033
1034 $text
1035 The text to show.
1036
1037 $page->TextRect($left, $top, $right, $bottom, $text, align)
1038 Print the text inside the specified region.
1039
1040 $left, $top, $right, $bottom
1041 Coordinates of corners of the region to output text.
1042
1043 $text
1044 The text to show.
1045
1046 align
1047 The alignment of the text. One of the following values
1048
1049 HPDF_TALIGN_LEFT
1050 HPDF_TALIGN_RIGHT
1051 HPDF_TALIGN_CENTER
1052 HPDF_TALIGN_JUSTIFY
1053
1054 $font->GetFontName()
1055 Gets the name of the font.
1056
1057 $font->GetEncodingName()
1058 Gets the encoding name of the font.
1059
1060 $font->GetUnicodeWidth($code)
1061 Gets the width of a Unicode character in a specific font.
1062
1063 my ($left, $bottom, $right, $top) = $font->GetBBox($code)
1064 Gets the bounding box of the font.
1065
1066 $font->GetAscent()
1067 Gets the vertical ascent of the font.
1068
1069 $font->GetDescent()
1070 Gets the vertical descent of the font.
1071
1072 $font->GetXHeight()
1073 Gets the distance from the baseline of lowercase letters.
1074
1075 $font->GetCapHeight()
1076 Gets the distance from the baseline of uppercase letters.
1077
1078 my ($numchars, $numwords, $width, $numspace) = $font->TextWidth($text,$len)
1079 Gets total width of the text, number of characters, and number of
1080 words.
1081
1082 $text
1083 The text to get width.
1084
1085 $len
1086 The byte length of the text.
1087
1088 $font->MeasureText($text,$len,$width,$font_size,$char_space,$word_space,$wordwrap)
1089 Calculates the byte length which can be included within the specified
1090 width.
1091
1092 $text
1093 The text to use for calculation.
1094
1095 $len
1096 The length of the text.
1097
1098 $width
1099 The width of the area to put the text.
1100
1101 $font_size
1102 The size of the font.
1103
1104 $char_space
1105 The character spacing.
1106
1107 $word_space
1108 The word spacing.
1109
1110 $wordwrap
1111 Suppose there are three words: "ABCDE", "FGH", and "IJKL". Also,
1112 suppose the substring until "J" can be included within the width
1113 (12 bytes). If word_wrap is HPDF_TRUE the function returns 12. If
1114 word_wrap parameter is HPDF_FALSE, it returns 10 (the end of the
1115 previous word).
1116
1117 $annotation->LinkAnnot_SetHighlightMode(mode)
1118 Defines the appearance when a mouse clicks on a link annotation.
1119
1120 mode - One of the following values:
1121
1122 HPDF_ANNOT_NO_HIGHTLIGHT No highlighting.
1123 HPDF_ANNOT_INVERT_BOX Invert the contents of the area of annotation.
1124 HPDF_ANNOT_INVERT_BORDER Invert the annotation's border.
1125 HPDF_ANNOT_DOWN_APPEARANCE Dent the annotation.
1126
1127 $annotation->LinkAnnot_SetBorderStyle($width,$dash_on,$dash_off)
1128 Defines the style of the annotation's border.
1129
1130 $width
1131 The width of an annotation's border.
1132
1133 $dash_on,$dash_off
1134 The dash style.
1135
1136 $annotation->TextAnnot_SetIcon(icon)
1137 Defines the appearance when a mouse clicks on a link annotation.
1138
1139 icon - The style of icon. The following values are available.
1140
1141 HPDF_ANNOT_ICON_COMMENT
1142 HPDF_ANNOT_ICON_KEY
1143 HPDF_ANNOT_ICON_NOTE
1144 HPDF_ANNOT_ICON_HELP
1145 HPDF_ANNOT_ICON_NEW_PARAGRAPH
1146 HPDF_ANNOT_ICON_PARAGRAPH
1147 HPDF_ANNOT_ICON_INSERT
1148
1149 $annotation->TextAnnot_SetOpened($open)
1150 Defines whether the text-annotation is initially open.
1151
1152 $open
1153 HPDF_TRUE means the annotation initially displayed open.
1154
1155 $outline->SetOpened($opened)
1156 Sets whether this node is opened or not when the outline is displayed
1157 for the first time. $opened specify whether the node is opened or not.
1158
1159 $outline->SetDestination($dst)
1160 Sets a destination object which becomes to a target to jump when the
1161 outline is clicked. $dst specify the handle of an destination object.
1162
1163 $destination->SetXYZ($left,$top,$zoom)
1164 Defines the appearance of a page with three parameters which are left,
1165 top and zoom.
1166
1167 $left
1168 The left coordinates of the page.
1169
1170 $top
1171 The top coordinates of the page.
1172
1173 $zoom
1174 The page magnified factor. The value must be between 0.08(8%) to
1175 32(%).
1176
1177 $destination->SetFit()
1178 Sets the appearance of the page to displaying entire page within the
1179 window.
1180
1181 $destination->SetFitH($top)
1182 Defines the appearance of a page to magnifying to fit the width of the
1183 page within the window and setting the top position of the page to the
1184 value of the "top" parameter.
1185
1186 $top
1187 The top coordinates of the page.
1188
1189 $destination->SetFitV($left)
1190 Defines the appearance of a page to magnifying to fit the height of the
1191 page within the window and setting the left position of the page to the
1192 value of the "top" parameter.
1193
1194 $left
1195 The left coordinates of the page.
1196
1197 $destination->SetFitR($left,$bottom,$right,$top)
1198 Defines the appearance of a page to magnifying the page to fit a
1199 rectangle specified by left, bottom, right and top.
1200
1201 $left
1202 The left coordinates of the page.
1203
1204 $bottom
1205 The bottom coordinates of the page.
1206
1207 $right
1208 The right coordinates of the page.
1209
1210 $top
1211 The top coordinates of the page.
1212
1213 $destination->SetFitB()
1214 Sets the appearance of the page to magnifying to fit the bounding box
1215 of the page within the window.
1216
1217 $destination->SetFitBH($top)
1218 Defines the appearance of a page to magnifying to fit the width of the
1219 bounding box of the page within the window and setting the top position
1220 of the page to the value of the "top" parameter.
1221
1222 $top
1223 The top coordinates of the page.
1224
1225 $destination->SetFitBV($top)
1226 Defines the appearance of a page to magnifying to fit the height of the
1227 bounding box of the page within the window and setting the top position
1228 of the page to the value of the "top" parameter.
1229
1230 $top
1231 The top coordinates of the page.
1232
1233 my ($x,$y) = $image->GetSize()
1234 Gets the size of the image of an image object.
1235
1236 $image->GetWidth()
1237 Gets the width of the image of an image object.
1238
1239 $image->GetHeight()
1240 Gets the height of the image of an image object.
1241
1242 $image->GetBitsPerComponent()
1243 Gets the number of bits used to describe each color component.
1244
1245 $image->GetColorSpace()
1246 Gets the name of the image's color space. It returns the following
1247 values
1248
1249 "DeviceGray"
1250 "DeviceRGB"
1251 "DeviceCMYK"
1252 "Indexed"
1253
1254 $image->SetColorMask ($rmin, $rmax, $gmin, $gmax, $bmin, $bmax)
1255 Sets the transparent color of the image by the RGB range values. The
1256 color within the range is displayed as a transparent color. The Image
1257 must be RGB color space.
1258
1259 $rmin
1260 The lower limit of Red. It must be between 0 and 255.
1261
1262 $rmax
1263 The upper limit of Red. It must be between 0 and 255.
1264
1265 $gmin
1266 The lower limit of Green. It must be between 0 and 255.
1267
1268 $gmax
1269 The upper limit of Green. It must be between 0 and 255.
1270
1271 $bmin
1272 The lower limit of Blue. It must be between 0 and 255.
1273
1274 $bmax
1275 The upper limit of Blue. It must be between 0 and 255.
1276
1277 $image->SetMaskImage($mask_image)
1278 Sets the mask image.
1279
1280 $mask_image specify the handle of an image object which is used as
1281 image-mask. This image must be 1bit gray-scale color image.
1282
1284 http://libharu.org/
1285
1287 Ilya Butakov, butilw@gmail.com
1288
1290 Copyright (C) 2008 by Ilya Butakov
1291
1292 This library is free software; you can redistribute it and/or modify it
1293 under the same terms as Perl itself, either Perl version 5.8.8 or, at
1294 your option, any later version of Perl 5 you may have available.
1295
1297 Hey! The above document had some coding errors, which are explained
1298 below:
1299
1300 Around line 913:
1301 Non-ASCII character seen before =encoding in '−,'. Assuming UTF-8
1302
1303
1304
1305perl v5.28.1 2008-09-14 PDF::Haru(3)