Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page cache option to save memory #474

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f7b000d
Fix SPDX license ID (#591)
remicollet Sep 6, 2023
70b63fa
Applied fix found by BrainforgeUK in Issue #564 (#620)
kosmro Sep 6, 2023
fc6faf6
README: tone down the warning about tc-lib-pdf (#589)
rubo77 Sep 6, 2023
7734617
Fix of Deprecation warning with php 8.1 #614 (#615)
johnson361 Sep 6, 2023
35e4147
Fixes for PHP 8.2 in tcpdf_fonts.php - fixes #632 (#633)
littlepackage Sep 6, 2023
de332db
php 8+ edge cases fixes (#630)
bruno-farias Sep 6, 2023
7e3fb6f
Fix composite glyph output (#581)
ren1244 Sep 6, 2023
9c7982d
fix for #583 (#584)
simonbuehler Sep 6, 2023
b142eba
Fix non-numeric value warning (#627)
d-salerno Sep 6, 2023
26d2eed
Fixed problems with S25 barcode (#611)
theonlytruth Sep 6, 2023
548c0f2
Check fonts files with phpstan too (#575)
mvorisek Sep 6, 2023
128b268
Fix return type annotation (#613)
survik1 Sep 6, 2023
18d1b2b
Typehints for getHeaderMargin() and setHeaderMargin() are inconsisten…
fisharebest Sep 6, 2023
f209e39
Bump version
nicolaasuni Sep 6, 2023
96985b9
Update copyright year
nicolaasuni Sep 6, 2023
73d8186
Bump actions/checkout and add PHP 8.3 (#642)
williamdes Sep 6, 2023
e3a8409
Update the CHANGELOG for 6.6.3 (#643)
williamdes Sep 6, 2023
31b9389
Bump version
nicolaasuni Sep 6, 2023
3ca051c
Fix corrupted file
nicolaasuni Sep 6, 2023
037283c
Simplify test matrix
nicolaasuni Sep 6, 2023
7689851
Remove duplicate settings
nicolaasuni Sep 6, 2023
5fce932
Adjust automation test settings
nicolaasuni Sep 6, 2023
178eb82
Add page cache option to save memory
ssigwart Jan 25, 2022
3a7d97f
Review fixes
ssigwart Jan 25, 2022
fb79d56
More review updates
ssigwart Jan 28, 2022
df109d8
Array updates
ssigwart Jan 28, 2022
91eec42
Swap static variable for shared reference to object
ssigwart Aug 4, 2023
f186d90
Fix unit test failure
ssigwart Oct 24, 2023
38b38a9
Page cache PHP 5.3 support
ssigwart Oct 24, 2023
677f53f
Page cache PHP 5.3 support in tests
ssigwart Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/lint-docs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: lint php documentation

permissions:
contents: read

on:
push:
branches:
Expand All @@ -12,7 +15,7 @@ jobs:
lint-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: lint php documentation
uses: sudo-bot/action-doctum@dev
with:
Expand Down
64 changes: 25 additions & 39 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Run tests

env:
XDEBUG_MODE: coverage

permissions:
contents: read

on:
push:
branches:
Expand All @@ -16,45 +22,26 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ["5.3", "5.4", "5.5", "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
os: [macos-latest, windows-latest]
php-version: ["7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
os: [ubuntu-latest]
experimental: [false]
php-extensions: ["bcmath, imagick, gd"]
coverage-extension: ["none"]
exclude:
# For now, we do not know how to run workflow on Windows
# with imagick PHP extension for PHP 5.3 - 5.6
- { php-version: '5.3', os: windows-latest }
- { php-version: '5.4', os: windows-latest }
- { php-version: '5.5', os: windows-latest }
- { php-version: '5.6', os: windows-latest }
# Somehow some tests fail under Windows and PHP 7.0,
# so we disable that run for now
- { php-version: '7.0', os: windows-latest }
# Add more specific tests
include:
- { php-version: '5.3', os: windows-latest, experimental: false, php-extensions: 'bcmath, gd', coverage-extension: 'none' }
- { php-version: '5.4', os: windows-latest, experimental: false, php-extensions: 'bcmath, gd', coverage-extension: 'none' }
- { php-version: '5.5', os: windows-latest, experimental: false, php-extensions: 'bcmath, gd', coverage-extension: 'none' }
- { php-version: '5.6', os: windows-latest, experimental: false, php-extensions: 'bcmath, gd', coverage-extension: 'none' }
# Specify coverage extension for Ubuntu runs
- { php-version: '5.3', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.4', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.5', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.6', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '7.0', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
# pcov is available from PHP 7.1
- { php-version: '7.1', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '7.2', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '7.3', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '7.4', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '8.0', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '8.1', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '8.2', os: ubuntu-latest, experimental: false, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: 'nightly', os: ubuntu-latest, experimental: true, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: '5.3', experimental: false, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.4', experimental: false, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.5', experimental: false, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '5.6', experimental: false, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '7.0', experimental: false, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'xdebug' }
- { php-version: '8.2', experimental: false, os: macos-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'none' }
- { php-version: '8.2', experimental: false, os: windows-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'none' }
- { php-version: '8.3', experimental: true, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
- { php-version: 'nightly', experimental: true, os: ubuntu-latest, php-extensions: 'bcmath, imagick, gd', coverage-extension: 'pcov' }
env:
PDFINFO_BINARY: ${{ (matrix.os == 'ubuntu-latest') && '/usr/bin/pdfinfo' || ((matrix.os == 'macos-latest') && '/usr/local/bin/pdfinfo' || 'C:\ProgramData\Chocolatey\bin\pdfinfo.exe') }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install pdfinfo, pdftopng or pdftoppm
uses: ConorMacBride/install-package@v1
with:
Expand Down Expand Up @@ -86,9 +73,9 @@ jobs:
path: ~/.composer/cache/
key: composer-cache
- name: Install dependencies
run: composer install --no-interaction
run: composer update --no-interaction
- name: Install test dependencies
run: cd ./tests && composer install --no-interaction && cd ../
run: cd ./tests && composer update --no-interaction && cd ../
- name: Run shell-based test suite
if: runner.os == 'Linux'
run: ./tests/launch.sh
Expand Down Expand Up @@ -118,12 +105,11 @@ jobs:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use php 8.0
- uses: actions/checkout@v4
- name: Use php 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
tools: composer:v2
php-version: 8.2
- name: Cache module
uses: actions/cache@v3
with:
Expand All @@ -132,4 +118,4 @@ jobs:
- name: Install phpstan
run: composer require --dev phpstan/phpstan
- name: Analyse files
run: ./vendor/bin/phpstan --memory-limit=2G
run: ./vendor/bin/phpstan --memory-limit=6G
20 changes: 20 additions & 0 deletions CHANGELOG.TXT
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
6.6.5 (2023-09-06)
- Fix corrupted file.

6.6.4 (2023-09-06)
- Fix GitHub automation tests.

6.6.3 (2023-09-06)
- Fix SPDX license ID (#591)
- Fix warning "array offset on value of type null" (#620)
- Improve the README about the status of this library (#589)
- Fix deprecation warning with PHP 8.1 (#614)
- Fixes for PHP 8.2 in tcpdf_fonts.php (#632)
- Fix some php 8+ edge cases (#630)
- Fix composite glyph output (#581)
- Fix "access array offset on value of type bool" with PDF/A (#583)
- Fix non-numeric value warning (#627)
- Fix issues with S25 barcode (#611)
- Fix return type annotations (#613)
- Fix some inconsistencies in type hints (#598)

6.6.2 (2022-12-17)
- Ensure pregSplit return type is always array.
- Add ability to run tests on various operating systems (#566)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

2002-2022 Nicola Asuni - Tecnick.com LTD
2002-2023 Nicola Asuni - Tecnick.com LTD

**********************************************************************
**********************************************************************
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

* **category** Library
* **author** Nicola Asuni <info@tecnick.com>
* **copyright** 2002-2022 Nicola Asuni - Tecnick.com LTD
* **copyright** 2002-2023 Nicola Asuni - Tecnick.com LTD
* **license** http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
* **link** http://www.tcpdf.org
* **source** https://github.com/tecnickcom/TCPDF


## IMPORTANT
A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this version will not receive any additional development or support.
This version should be considered obsolete, new projects should use the new version as soon it will become stable.
## NOTE
A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode.



Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.2
6.6.5
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"barcodes"
],
"homepage": "http://www.tcpdf.org/",
"version": "6.6.2",
"license": "LGPL-3.0-only",
"version": "6.6.5",
"license": "LGPL-3.0-or-later",
"authors": [
{
"name": "Nicola Asuni",
Expand Down
109 changes: 109 additions & 0 deletions examples/example_068.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
//============================================================+
// File name : example_068.php
// Begin : 2022-01-25
// Last Update : 2022-01-25
//
// Description : Example 068 for TCPDF class
// Creates an memory intensive PDF document using TCPDF
//============================================================+

// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 068');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 068', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
$pdf->SetFont('helvetica', '', 14, '', true);

// Add a page
$pdf->AddPage();

// Use page cache. Up to 2mb of the cache will be stored in memory. Overflow will be saved to a temporary file
$pageCacheSize = 2;
$pdf->usePageCacheFile($pageCacheSize);

// Write a lot of cells
$cols = array('A', 'B', 'C', 'D', 'E');
$colWidth = 160 / count($cols);
$lastColIdx = count($cols) - 1;
for ($i = 0; $i < 5000; $i++)
{
$page = $pdf->getPage();
$y = $pdf->getY();
$x = $pdf->getX();
foreach ($cols as $idx=>$col)
{
$pdf->MultiCell($colWidth, 6, str_repeat($col . $i, 3), 1, 'C');
$x += $colWidth;
if ($idx !== $lastColIdx)
{
if ($pdf->getPage() !== $page)
{
// Page break happened, so go back to previous page
$pdf->setPage($page);
}

$pdf->setY($y);
$pdf->setX($x);
}
}
}

// Copy page will restore page from cache
$pdf->copyPage(1);

// ---------------------------------------------------------

// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('example_068.pdf', 'I');

// Show memory usage
// These will cause tests to fail, so leave them commented out, but you can use them to debug.
// fputs(STDERR, 'Page cache size: ' . $pageCacheSize . 'MB' . PHP_EOL);
// fputs(STDERR, sprintf('Peak memory: %0.03fMB', memory_get_peak_usage() / 1024 / 1024) . PHP_EOL);

//============================================================+
// END OF FILE
//============================================================+
1 change: 1 addition & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<li>PDF/A-1b (ISO 19005-1:2005) document: [<a href="example_065.php" title="PDF [new window]" target="_blank">PDF</a>]</li>
<li>Using WriteHTMLCell: [<a href="example_066.php" title="PDF [new window]" target="_blank">PDF</a>]</li>
<li>Shorthand border styles including !important: [<a href="example_067.php" title="PDF [new window]" target="_blank">PDF</a>]</li>
<li>Using page cache to reduce memory usage: [<a href="example_068.php" title="PDF [new window]" target="_blank">PDF</a>]</li>
</ol>

<h2>Barcodes</h2>
Expand Down
1 change: 1 addition & 0 deletions include/barcodes/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ protected function getCode() {
if ($col >= $this->rsblocks[0]['dataLength']) {
$row += $this->b1;
}
$row = (int) $row;
$ret = $this->rsblocks[$row]['data'][$col];
} elseif ($this->count < $this->dataLength + $this->eccLength) {
$row = ($this->count - $this->dataLength) % $this->blocks;
Expand Down
Loading