Spaces:
Running
Running
File size: 31,035 Bytes
3c778ff | 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | import { Color } from "./colors";
import PDFDocument from "./PDFDocument";
import PDFEmbeddedPage from "./PDFEmbeddedPage";
import PDFFont from "./PDFFont";
import PDFImage from "./PDFImage";
import { PDFPageDrawCircleOptions, PDFPageDrawEllipseOptions, PDFPageDrawImageOptions, PDFPageDrawLineOptions, PDFPageDrawPageOptions, PDFPageDrawRectangleOptions, PDFPageDrawSquareOptions, PDFPageDrawSVGOptions, PDFPageDrawTextOptions } from "./PDFPageOptions";
import { Rotation } from "./rotations";
import { PDFOperator, PDFPageLeaf, PDFRef } from "../core";
/**
* Represents a single page of a [[PDFDocument]].
*/
export default class PDFPage {
/**
* > **NOTE:** You probably don't want to call this method directly. Instead,
* > consider using the [[PDFDocument.addPage]] and [[PDFDocument.insertPage]]
* > methods, which can create instances of [[PDFPage]] for you.
*
* Create an instance of [[PDFPage]] from an existing leaf node.
*
* @param leafNode The leaf node to be wrapped.
* @param ref The unique reference for the page.
* @param doc The document to which the page will belong.
*/
static of: (leafNode: PDFPageLeaf, ref: PDFRef, doc: PDFDocument) => PDFPage;
/**
* > **NOTE:** You probably don't want to call this method directly. Instead,
* > consider using the [[PDFDocument.addPage]] and [[PDFDocument.insertPage]]
* > methods, which can create instances of [[PDFPage]] for you.
*
* Create an instance of [[PDFPage]].
*
* @param doc The document to which the page will belong.
*/
static create: (doc: PDFDocument) => PDFPage;
/** The low-level PDFDictionary wrapped by this page. */
readonly node: PDFPageLeaf;
/** The unique reference assigned to this page within the document. */
readonly ref: PDFRef;
/** The document to which this page belongs. */
readonly doc: PDFDocument;
private fontKey?;
private font?;
private fontSize;
private fontColor;
private lineHeight;
private x;
private y;
private contentStream?;
private contentStreamRef?;
private constructor();
/**
* Rotate this page by a multiple of 90 degrees. For example:
* ```js
* import { degrees } from 'pdf-lib'
*
* page.setRotation(degrees(-90))
* page.setRotation(degrees(0))
* page.setRotation(degrees(90))
* page.setRotation(degrees(180))
* page.setRotation(degrees(270))
* ```
* @param angle The angle to rotate this page.
*/
setRotation(angle: Rotation): void;
/**
* Get this page's rotation angle in degrees. For example:
* ```js
* const rotationAngle = page.getRotation().angle;
* ```
* @returns The rotation angle of the page in degrees (always a multiple of
* 90 degrees).
*/
getRotation(): Rotation;
/**
* Resize this page by increasing or decreasing its width and height. For
* example:
* ```js
* page.setSize(250, 500)
* page.setSize(page.getWidth() + 50, page.getHeight() + 100)
* page.setSize(page.getWidth() - 50, page.getHeight() - 100)
* ```
*
* Note that the PDF specification does not allow for pages to have explicit
* widths and heights. Instead it defines the "size" of a page in terms of
* five rectangles: the MediaBox, CropBox, BleedBox, TrimBox, and ArtBox. As a
* result, this method cannot directly change the width and height of a page.
* Instead, it works by adjusting these five boxes.
*
* This method performs the following steps:
* 1. Set width & height of MediaBox.
* 2. Set width & height of CropBox, if it has same dimensions as MediaBox.
* 3. Set width & height of BleedBox, if it has same dimensions as MediaBox.
* 4. Set width & height of TrimBox, if it has same dimensions as MediaBox.
* 5. Set width & height of ArtBox, if it has same dimensions as MediaBox.
*
* This approach works well for most PDF documents as all PDF pages must
* have a MediaBox, but relatively few have a CropBox, BleedBox, TrimBox, or
* ArtBox. And when they do have these additional boxes, they often have the
* same dimensions as the MediaBox. However, if you find this method does not
* work for your document, consider setting the boxes directly:
* * [[PDFPage.setMediaBox]]
* * [[PDFPage.setCropBox]]
* * [[PDFPage.setBleedBox]]
* * [[PDFPage.setTrimBox]]
* * [[PDFPage.setArtBox]]
*
* @param width The new width of the page.
* @param height The new height of the page.
*/
setSize(width: number, height: number): void;
/**
* Resize this page by increasing or decreasing its width. For example:
* ```js
* page.setWidth(250)
* page.setWidth(page.getWidth() + 50)
* page.setWidth(page.getWidth() - 50)
* ```
*
* This method uses [[PDFPage.setSize]] to set the page's width.
*
* @param width The new width of the page.
*/
setWidth(width: number): void;
/**
* Resize this page by increasing or decreasing its height. For example:
* ```js
* page.setHeight(500)
* page.setHeight(page.getWidth() + 100)
* page.setHeight(page.getWidth() - 100)
* ```
*
* This method uses [[PDFPage.setSize]] to set the page's height.
*
* @param height The new height of the page.
*/
setHeight(height: number): void;
/**
* Set the MediaBox of this page. For example:
* ```js
* const mediaBox = page.getMediaBox()
*
* page.setMediaBox(0, 0, 250, 500)
* page.setMediaBox(mediaBox.x, mediaBox.y, 50, 100)
* page.setMediaBox(15, 5, mediaBox.width - 50, mediaBox.height - 100)
* ```
*
* See [[PDFPage.getMediaBox]] for details about what the MediaBox represents.
*
* @param x The x coordinate of the lower left corner of the new MediaBox.
* @param y The y coordinate of the lower left corner of the new MediaBox.
* @param width The width of the new MediaBox.
* @param height The height of the new MediaBox.
*/
setMediaBox(x: number, y: number, width: number, height: number): void;
/**
* Set the CropBox of this page. For example:
* ```js
* const cropBox = page.getCropBox()
*
* page.setCropBox(0, 0, 250, 500)
* page.setCropBox(cropBox.x, cropBox.y, 50, 100)
* page.setCropBox(15, 5, cropBox.width - 50, cropBox.height - 100)
* ```
*
* See [[PDFPage.getCropBox]] for details about what the CropBox represents.
*
* @param x The x coordinate of the lower left corner of the new CropBox.
* @param y The y coordinate of the lower left corner of the new CropBox.
* @param width The width of the new CropBox.
* @param height The height of the new CropBox.
*/
setCropBox(x: number, y: number, width: number, height: number): void;
/**
* Set the BleedBox of this page. For example:
* ```js
* const bleedBox = page.getBleedBox()
*
* page.setBleedBox(0, 0, 250, 500)
* page.setBleedBox(bleedBox.x, bleedBox.y, 50, 100)
* page.setBleedBox(15, 5, bleedBox.width - 50, bleedBox.height - 100)
* ```
*
* See [[PDFPage.getBleedBox]] for details about what the BleedBox represents.
*
* @param x The x coordinate of the lower left corner of the new BleedBox.
* @param y The y coordinate of the lower left corner of the new BleedBox.
* @param width The width of the new BleedBox.
* @param height The height of the new BleedBox.
*/
setBleedBox(x: number, y: number, width: number, height: number): void;
/**
* Set the TrimBox of this page. For example:
* ```js
* const trimBox = page.getTrimBox()
*
* page.setTrimBox(0, 0, 250, 500)
* page.setTrimBox(trimBox.x, trimBox.y, 50, 100)
* page.setTrimBox(15, 5, trimBox.width - 50, trimBox.height - 100)
* ```
*
* See [[PDFPage.getTrimBox]] for details about what the TrimBox represents.
*
* @param x The x coordinate of the lower left corner of the new TrimBox.
* @param y The y coordinate of the lower left corner of the new TrimBox.
* @param width The width of the new TrimBox.
* @param height The height of the new TrimBox.
*/
setTrimBox(x: number, y: number, width: number, height: number): void;
/**
* Set the ArtBox of this page. For example:
* ```js
* const artBox = page.getArtBox()
*
* page.setArtBox(0, 0, 250, 500)
* page.setArtBox(artBox.x, artBox.y, 50, 100)
* page.setArtBox(15, 5, artBox.width - 50, artBox.height - 100)
* ```
*
* See [[PDFPage.getArtBox]] for details about what the ArtBox represents.
*
* @param x The x coordinate of the lower left corner of the new ArtBox.
* @param y The y coordinate of the lower left corner of the new ArtBox.
* @param width The width of the new ArtBox.
* @param height The height of the new ArtBox.
*/
setArtBox(x: number, y: number, width: number, height: number): void;
/**
* Get this page's width and height. For example:
* ```js
* const { width, height } = page.getSize()
* ```
*
* This method uses [[PDFPage.getMediaBox]] to obtain the page's
* width and height.
*
* @returns The width and height of the page.
*/
getSize(): {
width: number;
height: number;
};
/**
* Get this page's width. For example:
* ```js
* const width = page.getWidth()
* ```
*
* This method uses [[PDFPage.getSize]] to obtain the page's size.
*
* @returns The width of the page.
*/
getWidth(): number;
/**
* Get this page's height. For example:
* ```js
* const height = page.getHeight()
* ```
*
* This method uses [[PDFPage.getSize]] to obtain the page's size.
*
* @returns The height of the page.
*/
getHeight(): number;
/**
* Get the rectangle defining this page's MediaBox. For example:
* ```js
* const { x, y, width, height } = page.getMediaBox()
* ```
*
* The MediaBox of a page defines the boundaries of the physical medium on
* which the page is to be displayed/printed. It may include extended area
* surrounding the page content for bleed marks, printing marks, etc...
* It may also include areas close to the edges of the medium that cannot be
* marked because of physical limitations of the output device. Content
* falling outside this boundary may safely be discarded without affecting
* the meaning of the PDF file.
*
* @returns An object defining the lower left corner of the MediaBox and its
* width & height.
*/
getMediaBox(): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Get the rectangle defining this page's CropBox. For example:
* ```js
* const { x, y, width, height } = page.getCropBox()
* ```
*
* The CropBox of a page defines the region to which the contents of the page
* shall be clipped when displayed or printed. Unlike the other boxes, the
* CropBox does not necessarily represent the physical page geometry. It
* merely imposes clipping on the page contents.
*
* The CropBox's default value is the page's MediaBox.
*
* @returns An object defining the lower left corner of the CropBox and its
* width & height.
*/
getCropBox(): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Get the rectangle defining this page's BleedBox. For example:
* ```js
* const { x, y, width, height } = page.getBleedBox()
* ```
*
* The BleedBox of a page defines the region to which the contents of the
* page shall be clipped when output in a production environment. This may
* include any extra bleed area needed to accommodate the physical
* limitations of cutting, folding, and trimming equipment. The actual
* printed page may include printing marks that fall outside the BleedBox.
*
* The BleedBox's default value is the page's CropBox.
*
* @returns An object defining the lower left corner of the BleedBox and its
* width & height.
*/
getBleedBox(): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Get the rectangle defining this page's TrimBox. For example:
* ```js
* const { x, y, width, height } = page.getTrimBox()
* ```
*
* The TrimBox of a page defines the intended dimensions of the finished
* page after trimming. It may be smaller than the MediaBox to allow for
* production-related content, such as printing instructions, cut marks, or
* color bars.
*
* The TrimBox's default value is the page's CropBox.
*
* @returns An object defining the lower left corner of the TrimBox and its
* width & height.
*/
getTrimBox(): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Get the rectangle defining this page's ArtBox. For example:
* ```js
* const { x, y, width, height } = page.getArtBox()
* ```
*
* The ArtBox of a page defines the extent of the page's meaningful content
* (including potential white space).
*
* The ArtBox's default value is the page's CropBox.
*
* @returns An object defining the lower left corner of the ArtBox and its
* width & height.
*/
getArtBox(): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Translate this page's content to a new location on the page. This operation
* is often useful after resizing the page with [[setSize]]. For example:
* ```js
* // Add 50 units of whitespace to the top and right of the page
* page.setSize(page.getWidth() + 50, page.getHeight() + 50)
*
* // Move the page's content from the lower-left corner of the page
* // to the top-right corner.
* page.translateContent(50, 50)
*
* // Now there are 50 units of whitespace to the left and bottom of the page
* ```
* See also: [[resetPosition]]
* @param x The new position on the x-axis for this page's content.
* @param y The new position on the y-axis for this page's content.
*/
translateContent(x: number, y: number): void;
/**
* Scale the size, content, and annotations of a page.
*
* For example:
* ```js
* page.scale(0.5, 0.5);
* ```
*
* @param x The factor by which the width for the page should be scaled
* (e.g. `0.5` is 50%).
* @param y The factor by which the height for the page should be scaled
* (e.g. `2.0` is 200%).
*/
scale(x: number, y: number): void;
/**
* Scale the content of a page. This is useful after resizing an existing
* page. This scales only the content, not the annotations.
*
* For example:
* ```js
* // Bisect the size of the page
* page.setSize(page.getWidth() / 2, page.getHeight() / 2);
*
* // Scale the content of the page down by 50% in x and y
* page.scaleContent(0.5, 0.5);
* ```
* See also: [[scaleAnnotations]]
* @param x The factor by which the x-axis for the content should be scaled
* (e.g. `0.5` is 50%).
* @param y The factor by which the y-axis for the content should be scaled
* (e.g. `2.0` is 200%).
*/
scaleContent(x: number, y: number): void;
/**
* Scale the annotations of a page. This is useful if you want to scale a
* page with comments or other annotations.
* ```js
* // Scale the content of the page down by 50% in x and y
* page.scaleContent(0.5, 0.5);
*
* // Scale the content of the page down by 50% in x and y
* page.scaleAnnotations(0.5, 0.5);
* ```
* See also: [[scaleContent]]
* @param x The factor by which the x-axis for the annotations should be
* scaled (e.g. `0.5` is 50%).
* @param y The factor by which the y-axis for the annotations should be
* scaled (e.g. `2.0` is 200%).
*/
scaleAnnotations(x: number, y: number): void;
/**
* Reset the x and y coordinates of this page to `(0, 0)`. This operation is
* often useful after calling [[translateContent]]. For example:
* ```js
* // Shift the page's contents up and to the right by 50 units
* page.translateContent(50, 50)
*
* // This text will shifted - it will be drawn at (50, 50)
* page.drawText('I am shifted')
*
* // Move back to (0, 0)
* page.resetPosition()
*
* // This text will not be shifted - it will be drawn at (0, 0)
* page.drawText('I am not shifted')
* ```
*/
resetPosition(): void;
/**
* Choose a default font for this page. The default font will be used whenever
* text is drawn on this page and no font is specified. For example:
* ```js
* import { StandardFonts } from 'pdf-lib'
*
* const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
* const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
* const courierFont = await pdfDoc.embedFont(StandardFonts.Courier)
*
* const page = pdfDoc.addPage()
*
* page.setFont(helveticaFont)
* page.drawText('I will be drawn in Helvetica')
*
* page.setFont(timesRomanFont)
* page.drawText('I will be drawn in Courier', { font: courierFont })
* ```
* @param font The default font to be used when drawing text on this page.
*/
setFont(font: PDFFont): void;
/**
* Choose a default font size for this page. The default font size will be
* used whenever text is drawn on this page and no font size is specified.
* For example:
* ```js
* page.setFontSize(12)
* page.drawText('I will be drawn in size 12')
*
* page.setFontSize(36)
* page.drawText('I will be drawn in size 24', { fontSize: 24 })
* ```
* @param fontSize The default font size to be used when drawing text on this
* page.
*/
setFontSize(fontSize: number): void;
/**
* Choose a default font color for this page. The default font color will be
* used whenever text is drawn on this page and no font color is specified.
* For example:
* ```js
* import { rgb, cmyk, grayscale } from 'pdf-lib'
*
* page.setFontColor(rgb(0.97, 0.02, 0.97))
* page.drawText('I will be drawn in pink')
*
* page.setFontColor(cmyk(0.4, 0.7, 0.39, 0.15))
* page.drawText('I will be drawn in gray', { color: grayscale(0.5) })
* ```
* @param fontColor The default font color to be used when drawing text on
* this page.
*/
setFontColor(fontColor: Color): void;
/**
* Choose a default line height for this page. The default line height will be
* used whenever text is drawn on this page and no line height is specified.
* For example:
* ```js
* page.setLineHeight(12);
* page.drawText('These lines will be vertically \n separated by 12 units')
*
* page.setLineHeight(36);
* page.drawText('These lines will be vertically \n separated by 24 units', {
* lineHeight: 24
* })
* ```
* @param lineHeight The default line height to be used when drawing text on
* this page.
*/
setLineHeight(lineHeight: number): void;
/**
* Get the default position of this page. For example:
* ```js
* const { x, y } = page.getPosition()
* ```
* @returns The default position of the page.
*/
getPosition(): {
x: number;
y: number;
};
/**
* Get the default x coordinate of this page. For example:
* ```js
* const x = page.getX()
* ```
* @returns The default x coordinate of the page.
*/
getX(): number;
/**
* Get the default y coordinate of this page. For example:
* ```js
* const y = page.getY()
* ```
* @returns The default y coordinate of the page.
*/
getY(): number;
/**
* Change the default position of this page. For example:
* ```js
* page.moveTo(0, 0)
* page.drawText('I will be drawn at the origin')
*
* page.moveTo(0, 25)
* page.drawText('I will be drawn 25 units up')
*
* page.moveTo(25, 25)
* page.drawText('I will be drawn 25 units up and 25 units to the right')
* ```
* @param x The new default position on the x-axis for this page.
* @param y The new default position on the y-axis for this page.
*/
moveTo(x: number, y: number): void;
/**
* Change the default position of this page to be further down the y-axis.
* For example:
* ```js
* page.moveTo(50, 50)
* page.drawText('I will be drawn at (50, 50)')
*
* page.moveDown(10)
* page.drawText('I will be drawn at (50, 40)')
* ```
* @param yDecrease The amount by which the page's default position along the
* y-axis should be decreased.
*/
moveDown(yDecrease: number): void;
/**
* Change the default position of this page to be further up the y-axis.
* For example:
* ```js
* page.moveTo(50, 50)
* page.drawText('I will be drawn at (50, 50)')
*
* page.moveUp(10)
* page.drawText('I will be drawn at (50, 60)')
* ```
* @param yIncrease The amount by which the page's default position along the
* y-axis should be increased.
*/
moveUp(yIncrease: number): void;
/**
* Change the default position of this page to be further left on the x-axis.
* For example:
* ```js
* page.moveTo(50, 50)
* page.drawText('I will be drawn at (50, 50)')
*
* page.moveLeft(10)
* page.drawText('I will be drawn at (40, 50)')
* ```
* @param xDecrease The amount by which the page's default position along the
* x-axis should be decreased.
*/
moveLeft(xDecrease: number): void;
/**
* Change the default position of this page to be further right on the y-axis.
* For example:
* ```js
* page.moveTo(50, 50)
* page.drawText('I will be drawn at (50, 50)')
*
* page.moveRight(10)
* page.drawText('I will be drawn at (60, 50)')
* ```
* @param xIncrease The amount by which the page's default position along the
* x-axis should be increased.
*/
moveRight(xIncrease: number): void;
/**
* Push one or more operators to the end of this page's current content
* stream. For example:
* ```js
* import {
* pushGraphicsState,
* moveTo,
* lineTo,
* closePath,
* setFillingColor,
* rgb,
* fill,
* popGraphicsState,
* } from 'pdf-lib'
*
* // Draw a green triangle in the lower-left corner of the page
* page.pushOperators(
* pushGraphicsState(),
* moveTo(0, 0),
* lineTo(100, 0),
* lineTo(50, 100),
* closePath(),
* setFillingColor(rgb(0.0, 1.0, 0.0)),
* fill(),
* popGraphicsState(),
* )
* ```
* @param operator The operators to be pushed.
*/
pushOperators(...operator: PDFOperator[]): void;
/**
* Draw one or more lines of text on this page. For example:
* ```js
* import { StandardFonts, rgb } from 'pdf-lib'
*
* const helveticaFont = await pdfDoc.embedFont(StandardFonts.Helvetica)
* const timesRomanFont = await pdfDoc.embedFont(StandardFonts.TimesRoman)
*
* const page = pdfDoc.addPage()
*
* page.setFont(helveticaFont)
*
* page.moveTo(5, 200)
* page.drawText('The Life of an Egg', { size: 36 })
*
* page.moveDown(36)
* page.drawText('An Epic Tale of Woe', { size: 30 })
*
* page.drawText(
* `Humpty Dumpty sat on a wall \n` +
* `Humpty Dumpty had a great fall; \n` +
* `All the king's horses and all the king's men \n` +
* `Couldn't put Humpty together again. \n`,
* {
* x: 25,
* y: 100,
* font: timesRomanFont,
* size: 24,
* color: rgb(1, 0, 0),
* lineHeight: 24,
* opacity: 0.75,
* },
* )
* ```
* @param text The text to be drawn.
* @param options The options to be used when drawing the text.
*/
drawText(text: string, options?: PDFPageDrawTextOptions): void;
/**
* Draw an image on this page. For example:
* ```js
* import { degrees } from 'pdf-lib'
*
* const jpgUrl = 'https://pdf-lib.js.org/assets/cat_riding_unicorn.jpg'
* const jpgImageBytes = await fetch(jpgUrl).then((res) => res.arrayBuffer())
*
* const jpgImage = await pdfDoc.embedJpg(jpgImageBytes)
* const jpgDims = jpgImage.scale(0.5)
*
* const page = pdfDoc.addPage()
*
* page.drawImage(jpgImage, {
* x: 25,
* y: 25,
* width: jpgDims.width,
* height: jpgDims.height,
* rotate: degrees(30),
* opacity: 0.75,
* })
* ```
* @param image The image to be drawn.
* @param options The options to be used when drawing the image.
*/
drawImage(image: PDFImage, options?: PDFPageDrawImageOptions): void;
/**
* Draw an embedded PDF page on this page. For example:
* ```js
* import { degrees } from 'pdf-lib'
*
* const pdfDoc = await PDFDocument.create()
* const page = pdfDoc.addPage()
*
* const sourcePdfUrl = 'https://pdf-lib.js.org/assets/with_large_page_count.pdf'
* const sourcePdf = await fetch(sourcePdfUrl).then((res) => res.arrayBuffer())
*
* // Embed page 74 from the PDF
* const [embeddedPage] = await pdfDoc.embedPdf(sourcePdf, 73)
*
* page.drawPage(embeddedPage, {
* x: 250,
* y: 200,
* xScale: 0.5,
* yScale: 0.5,
* rotate: degrees(30),
* opacity: 0.75,
* })
* ```
*
* The `options` argument accepts both `width`/`height` and `xScale`/`yScale`
* as options. Since each of these options defines the size of the drawn page,
* if both options are given, `width` and `height` take precedence and the
* corresponding scale variants are ignored.
*
* @param embeddedPage The embedded page to be drawn.
* @param options The options to be used when drawing the embedded page.
*/
drawPage(embeddedPage: PDFEmbeddedPage, options?: PDFPageDrawPageOptions): void;
/**
* Draw an SVG path on this page. For example:
* ```js
* import { rgb } from 'pdf-lib'
*
* const svgPath = 'M 0,20 L 100,160 Q 130,200 150,120 C 190,-40 200,200 300,150 L 400,90'
*
* // Draw path as black line
* page.drawSvgPath(svgPath, { x: 25, y: 75 })
*
* // Change border style and opacity
* page.drawSvgPath(svgPath, {
* x: 25,
* y: 275,
* borderColor: rgb(0.5, 0.5, 0.5),
* borderWidth: 2,
* borderOpacity: 0.75,
* })
*
* // Set fill color and opacity
* page.drawSvgPath(svgPath, {
* x: 25,
* y: 475,
* color: rgb(1.0, 0, 0),
* opacity: 0.75,
* })
*
* // Draw 50% of original size
* page.drawSvgPath(svgPath, {
* x: 25,
* y: 675,
* scale: 0.5,
* })
* ```
* @param path The SVG path to be drawn.
* @param options The options to be used when drawing the SVG path.
*/
drawSvgPath(path: string, options?: PDFPageDrawSVGOptions): void;
/**
* Draw a line on this page. For example:
* ```js
* import { rgb } from 'pdf-lib'
*
* page.drawLine({
* start: { x: 25, y: 75 },
* end: { x: 125, y: 175 },
* thickness: 2,
* color: rgb(0.75, 0.2, 0.2),
* opacity: 0.75,
* })
* ```
* @param options The options to be used when drawing the line.
*/
drawLine(options: PDFPageDrawLineOptions): void;
/**
* Draw a rectangle on this page. For example:
* ```js
* import { degrees, grayscale, rgb } from 'pdf-lib'
*
* page.drawRectangle({
* x: 25,
* y: 75,
* width: 250,
* height: 75,
* rotate: degrees(-15),
* borderWidth: 5,
* borderColor: grayscale(0.5),
* color: rgb(0.75, 0.2, 0.2),
* opacity: 0.5,
* borderOpacity: 0.75,
* })
* ```
* @param options The options to be used when drawing the rectangle.
*/
drawRectangle(options?: PDFPageDrawRectangleOptions): void;
/**
* Draw a square on this page. For example:
* ```js
* import { degrees, grayscale, rgb } from 'pdf-lib'
*
* page.drawSquare({
* x: 25,
* y: 75,
* size: 100,
* rotate: degrees(-15),
* borderWidth: 5,
* borderColor: grayscale(0.5),
* color: rgb(0.75, 0.2, 0.2),
* opacity: 0.5,
* borderOpacity: 0.75,
* })
* ```
* @param options The options to be used when drawing the square.
*/
drawSquare(options?: PDFPageDrawSquareOptions): void;
/**
* Draw an ellipse on this page. For example:
* ```js
* import { grayscale, rgb } from 'pdf-lib'
*
* page.drawEllipse({
* x: 200,
* y: 75,
* xScale: 100,
* yScale: 50,
* borderWidth: 5,
* borderColor: grayscale(0.5),
* color: rgb(0.75, 0.2, 0.2),
* opacity: 0.5,
* borderOpacity: 0.75,
* })
* ```
* @param options The options to be used when drawing the ellipse.
*/
drawEllipse(options?: PDFPageDrawEllipseOptions): void;
/**
* Draw a circle on this page. For example:
* ```js
* import { grayscale, rgb } from 'pdf-lib'
*
* page.drawCircle({
* x: 200,
* y: 150,
* size: 100,
* borderWidth: 5,
* borderColor: grayscale(0.5),
* color: rgb(0.75, 0.2, 0.2),
* opacity: 0.5,
* borderOpacity: 0.75,
* })
* ```
* @param options The options to be used when drawing the ellipse.
*/
drawCircle(options?: PDFPageDrawCircleOptions): void;
private setOrEmbedFont;
private getFont;
private resetFont;
private getContentStream;
private createContentStream;
private maybeEmbedGraphicsState;
private scaleAnnot;
}
//# sourceMappingURL=PDFPage.d.ts.map |