Skip to content

Commit

Permalink
Fixing and updating the Sample PDF generation
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-butti committed Jan 2, 2024
1 parent 118c235 commit 84b8def
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.0.8 - 2nd January 2024
- Fixing and updating the Sample PDF generation

## 1.0.7 - 31th December 2023
- Fixing Table of Content
- SetList::CODING_STYLE
Expand Down
55 changes: 44 additions & 11 deletions src/Commands/SampleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Ibis\Commands;

use Ibis\Ibis;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class SampleCommand extends Command
class SampleCommand extends BaseBuildCommand
{
/**
* Configure the command.
Expand All @@ -20,7 +20,21 @@ protected function configure()
$this
->setName('sample')
->addArgument('theme', InputArgument::OPTIONAL, 'The name of the theme', 'light')
->setDescription('Generate a sample.');
->addOption(
'content',
'c',
InputOption::VALUE_OPTIONAL,
'The path of the content directory',
''
)
->addOption(
'workingdir',
'd',
InputOption::VALUE_OPTIONAL,
'The path of the working directory where `ibis.php` and `assets` directory are located',
''
)
->setDescription('Generate a sample from the PDF.');
}

/**
Expand All @@ -31,17 +45,30 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$currentPath = getcwd();

$config = require $currentPath . '/ibis.php';

if (!$this->preExecute($input, $output)) {
return Command::INVALID;
}

$themeName = $input->getArgument('theme');

$pdfFilename = $this->config->workingPath . '/export/' . $this->config->outputFileName() . '-' . $themeName . '.pdf';


if (!$this->disk->isFile($pdfFilename)) {
$this->output->writeln('<fg=red> ⚠️ File ' . $pdfFilename . ' not exists (i need it for creating the sample)</>');
$this->output->writeln('<fg=yellow> Suggestion : try to execute `ibis-next pdf` before generating a sample</>');
return Command::FAILURE;
}

$mpdf = new \Mpdf\Mpdf();

$fileName = Ibis::outputFileName() . '-' . $input->getArgument('theme');

$mpdf->setSourceFile($currentPath . '/export/' . $fileName . '.pdf');

foreach ($config['sample'] as $range) {
$mpdf->setSourceFile($pdfFilename);

foreach ($this->config->config['sample'] as $range) {
foreach (range($range[0], $range[1]) as $page) {
$mpdf->useTemplate(
$mpdf->importPage($page)
Expand All @@ -50,11 +77,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$mpdf->WriteHTML('<p style="text-align: center; font-size: 16px; line-height: 40px;">' . $config['sample_notice'] . '</p>');

$mpdf->WriteHTML('<p style="text-align: center; font-size: 16px; line-height: 40px;">' . $this->config->config['sample_notice'] . '</p>');
$sampleFileName = $this->config->workingPath . '/export/sample-' . $this->config->outputFileName() . '-' . $themeName . '.pdf';
$this->output->writeln('<fg=yellow>==></> Writing Sample PDF To Disk ...');
$mpdf->Output(
$currentPath . '/export/sample-.' . $fileName . '.pdf'
$sampleFileName
);
$this->output->writeln('<fg=green> ✅ File ' . $sampleFileName . ' created</>');

$this->output->writeln('');
$this->output->writeln('✨✨ ' . $mpdf->page . ' PDF pages ✨✨');


return 0;
}
Expand Down
5 changes: 2 additions & 3 deletions stubs/ibis.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@
* Page ranges to be used with the sample command.
*/
'sample' => [
[1, 3],
[80, 85],
[100, 103],
[1, 7],
[15, 15]
],

/**
Expand Down

0 comments on commit 84b8def

Please sign in to comment.