-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kduma-OSS/feature/multipage
Process tagged multipage documents and output combined PDF files
- Loading branch information
Showing
10 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Actions; | ||
|
||
use App\Actions\Tools\RunDockerContainerAction; | ||
use App\Actions\Tools\Exceptions\PdfPageContentsExtractorException; | ||
use App\Actions\Tools\TemporaryDirectoryCreatorAction; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Str; | ||
use SplFileInfo; | ||
|
||
class PdfPagesJoinerAction | ||
{ | ||
public function __construct( | ||
protected RunDockerContainerAction $runDockerContainerAction, | ||
protected TemporaryDirectoryCreatorAction $tempDirMaker | ||
) {} | ||
|
||
public function execute(array|Collection $input_files, string|SplFileInfo $output_file): void | ||
{ | ||
if(is_string($output_file)) | ||
$output_file = new SplFileInfo($output_file); | ||
|
||
if(is_array($input_files)) | ||
$input_files = collect($input_files); | ||
|
||
$input_files = $input_files | ||
->map(function($input_file) { | ||
if(is_string($input_file)) | ||
return new SplFileInfo($input_file); | ||
|
||
return $input_file; | ||
}) | ||
->values() | ||
->mapWithKeys(fn(SplFileInfo $file, $index) => ['input-'.str_pad($index, 5, '0', STR_PAD_LEFT).'.pdf' => $file]); | ||
|
||
$temporaryDirectory = $this->tempDirMaker->create(); | ||
|
||
$input_files->each(function(SplFileInfo $input_file, $name) use ($temporaryDirectory) { | ||
copy($input_file->getPathname(), $temporaryDirectory->path($name)); | ||
}); | ||
|
||
$action = $this | ||
->runDockerContainerAction | ||
->withTemporaryDirectory($temporaryDirectory); | ||
|
||
$action->execute(dockerImageName: 'ghcr.io/kduma-oss/cli-pdf-scan-splitter/pdf-page-joiner',output: $output, return: $return); | ||
|
||
if (0 != $return) { | ||
$temporaryDirectory->delete(); | ||
throw new PdfPageContentsExtractorException( | ||
command: $action->getCommand(dockerImageName: 'ghcr.io/kduma-oss/cli-pdf-scan-splitter/pdf-page-joiner'), | ||
code: $return, | ||
output: $output, | ||
); | ||
} | ||
|
||
copy($temporaryDirectory->path('output.pdf'), $output_file->getPathname()); | ||
|
||
$temporaryDirectory->delete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM ubuntu:22.04 | ||
#FROM ubuntu:16.04 | ||
|
||
WORKDIR /src | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
poppler-utils \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
COPY run.sh run.sh | ||
|
||
WORKDIR /data | ||
|
||
ENTRYPOINT ["/src/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
/usr/bin/pdfunite /data/input-*.pdf '/data/output.pdf' || exit 1 |
Binary file not shown.
Binary file not shown.
Binary file not shown.