earthlinginteractive/oophpdf 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

earthlinginteractive/oophpdf

最新稳定版本:v0.0.5

Composer 安装命令:

composer require earthlinginteractive/oophpdf

包简介

An object-oriented wrapper for writing PDF documents using PHP and TCPDF

README 文档

README

An object-oriented wrapper for writing PDF documents using PHP and TCPDF

Description

OOPHPDF is a PHP library that provides an object-oriented interface to common TCPDF drawing methods. Examples of implemented objects include the MultiCell, Image, and a basic Table with Rows that contain cells. Instead of directly calling TCPDF methods to draw items, you create an object that represents the item you want to draw, configure it, query it as needed, then draw it.

Installation

OOPHPDF can be installed as a Composer module. If you're using Composer, you can install it with:

composer require earthlinginteractive/oophpdf

Why?

TCPDF is great for writing PDF documents, but its state-based design can be limiting when writing complex documents.

For example, try writing two MultiCell boxes side-by-side with different fonts, but make the height of both match the height of the tallest, so that they are only as tall as needed to fit the text of both. You'd need to set up the context for each box, determine its height, determine the largest height, then draw both boxes (which involves setting up the context for each again).

This library simplifies the problem by treating each item on the PDF as an object.

Using this library, you would create and configure an object for each box, find the height of each, determine the largest height, set that height on both boxes, then draw them. You're no longer responsible for setting up and restoring context; the objects maintain their own contexts.

Example

This example implements the problem described in the "Why" section, where two boxes of text with different font sizes are written next to each other with the same height.

The code below assumes the TCPDF object is already created with units in inches and a blank page in portrait Letter size. It also assumes you will output the PDF document afterwards. See the full example in example.php.

// create the left box
$leftBox = new OOPHPDF_MultiCell($pdf);
$leftBox
	->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.")
	->setFontSize(24)
	->setFontStyle('B')
	->setFillColorArray(array(255, 200, 200)) // light red
	->setLn(0)
	->setWidth(3.75)
	->setHeightToAuto();

// create the right box
$rightBox = new OOPHPDF_MultiCell($pdf);
$rightBox
	->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
	->setFontSize(16)
	->setFontStyle('I')
	->setFillColorArray(array(200, 200, 255)) // light blue
	->setLn(0)
	->setWidth(3.75)
	->setHeightToAuto();

// find the height of the tallest box
$maxHeight = max($leftBox->getHeight(), $rightBox->getHeight());

// make both boxes use the tallest height
$leftBox->setHeight($maxHeight);
$rightBox->setHeight($maxHeight);

// draw both boxes
$leftBox->drawAtPosition(0.5, 1);
$rightBox->drawAtPosition(4.25, 1);

统计信息

  • 总下载量: 6.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固