Skip to content

Commit 4f5290f

Browse files
Fixed demo writer
1 parent 6fe3f2b commit 4f5290f

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/demo-ltv.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
$settings = require 'settings.php';
2222

2323
$fileToSign = __DIR__ . '/assets/Laboratory-Report.pdf';
24-
$resultPath = 'signed.pdf';
2524

2625
// to create or update your access token you have to call generate-token.php first
2726
if (!isset($_SESSION['accessToken']['access_token'])) {
@@ -79,7 +78,7 @@
7978
$module->setSigningAlgorithm($_POST['algorithm']);
8079

8180
// create a writer instance
82-
$writer = new SetaPDF_Core_Writer_File($resultPath);
81+
$writer = new SetaPDF_Core_Writer_String();
8382
$tmpWriter = new SetaPDF_Core_Writer_TempFile();
8483
// create the document instance
8584
$document = SetaPDF_Core_Document::loadByFilename($fileToSign, $tmpWriter);
@@ -139,8 +138,8 @@
139138

140139
$document->save()->finish();
141140

142-
echo '<a href="data:application/pdf;base64,' . base64_encode(file_get_contents($resultPath)) . '" ' .
143-
'download="' . basename($resultPath) . '">download</a> | <a href="?">restart</a><br />';
141+
echo '<a href="data:application/pdf;base64,' . base64_encode($writer->getBuffer()) . '" ' .
142+
'download="result.pdf">download</a> | <a href="?">restart</a><br />';
144143

145144
} catch (Throwable $e) {
146145
echo 'An error occurred: <pre>' . $e . '</pre>';

examples/demo.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
$settings = require 'settings.php';
2222

2323
$fileToSign = __DIR__ . '/assets/Laboratory-Report.pdf';
24-
$resultPath = 'signed.pdf';
2524

2625
// to create or update your access token you have to call generate-token.php first
2726
if (!isset($_SESSION['accessToken']['access_token'])) {
@@ -77,7 +76,7 @@
7776
$module->setSigningAlgorithm($_POST['algorithm']);
7877

7978
// create a writer instance
80-
$writer = new SetaPDF_Core_Writer_File($resultPath);
79+
$writer = new SetaPDF_Core_Writer_String();
8180
// create the document instance
8281
$document = SetaPDF_Core_Document::loadByFilename($fileToSign, $writer);
8382

@@ -86,8 +85,8 @@
8685
$signer->setReason('Testing Cumulo!');
8786
$signer->sign($module);
8887

89-
echo '<a href="data:application/pdf;base64,' . base64_encode(file_get_contents($resultPath)) . '" ' .
90-
'download="' . basename($resultPath) . '">download</a> | <a href="?">restart</a><br />';
88+
echo '<a href="data:application/pdf;base64,' . base64_encode($writer->getBuffer()) . '" ' .
89+
'download="result.pdf">download</a> | <a href="?">restart</a><br />';
9190

9291
} catch (Throwable $e) {
9392
echo 'An error occurred: <pre>' . $e . '</pre>';

0 commit comments

Comments
 (0)