diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/CopiesOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/CopiesOption.php
index d2ba0ed0..42f79dd6 100644
--- a/src/Backend/WkHtmlToPdf/ExtraOption/CopiesOption.php
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/CopiesOption.php
@@ -8,6 +8,9 @@
final class CopiesOption implements ExtraOption
{
+ /**
+ * @param positive-int $number
+ */
public function __construct(private readonly int $number) {}
public function compile(): array
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/DpiOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/DpiOption.php
index 65502d9f..ab0dc067 100644
--- a/src/Backend/WkHtmlToPdf/ExtraOption/DpiOption.php
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/DpiOption.php
@@ -8,6 +8,9 @@
final class DpiOptions implements ExtraOption
{
+ /**
+ * @param positive-int $dpi
+ */
public function __construct(private readonly int $dpi) {}
public function compile(): array
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/GrayscaleOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/GrayscaleOption.php
index 21ed0645..2b6b82c7 100644
--- a/src/Backend/WkHtmlToPdf/ExtraOption/GrayscaleOption.php
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/GrayscaleOption.php
@@ -4,7 +4,9 @@
namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
-final class GrayscaleOption
+use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
+
+final class GrayscaleOption implements ExtraOption
{
public function __construct() {}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/ImageDpiOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/ImageDpiOption.php
index d1ec313d..2e9cd76f 100644
--- a/src/Backend/WkHtmlToPdf/ExtraOption/ImageDpiOption.php
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/ImageDpiOption.php
@@ -4,7 +4,17 @@
namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
-final class ImageDpiOption
+use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
+
+final class ImageDpiOption implements ExtraOption
{
+ /**
+ * @param positive-int $dpi
+ */
public function __construct(public readonly int $dpi) {}
+
+ public function compile(): array
+ {
+ return ['--image-dpi', $this->dpi];
+ }
}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/ImageQualityOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/ImageQualityOption.php
new file mode 100644
index 00000000..068f204b
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/ImageQualityOption.php
@@ -0,0 +1,20 @@
+quality];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/LowQualityOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/LowQualityOption.php
new file mode 100644
index 00000000..cf22d505
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/LowQualityOption.php
@@ -0,0 +1,17 @@
+margin];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/MarginLeftOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/MarginLeftOption.php
new file mode 100644
index 00000000..5d840673
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/MarginLeftOption.php
@@ -0,0 +1,17 @@
+margin];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/MarginRightOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/MarginRightOption.php
new file mode 100644
index 00000000..9f455bb0
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/MarginRightOption.php
@@ -0,0 +1,17 @@
+margin];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/MarginTopOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/MarginTopOption.php
new file mode 100644
index 00000000..4d777883
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/MarginTopOption.php
@@ -0,0 +1,17 @@
+margin];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/NoCollateOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/NoCollateOption.php
index eb0e740c..db44f679 100644
--- a/src/Backend/WkHtmlToPdf/ExtraOption/NoCollateOption.php
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/NoCollateOption.php
@@ -4,7 +4,14 @@
namespace KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
-final class NoCollateOption
+use KNPLabs\Snappy\Backend\WkHtmlToPdf\ExtraOption;
+
+final class NoCollateOption implements ExtraOption
{
public function __construct() {}
+
+ public function compile(): array
+ {
+ return ['--no-collate'];
+ }
}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/NoPdfCompressionOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/NoPdfCompressionOption.php
new file mode 100644
index 00000000..d3d07cb4
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/NoPdfCompressionOption.php
@@ -0,0 +1,17 @@
+ ExtraOption\Orientation\Value::PORTRAIT,
+ PageOrientation::LANDSCAPE => ExtraOption\Orientation\Value::LANDSCAPE,
+ }
+ );
+ }
+
+ public function compile(): array
+ {
+ return ['--orientation', $this->orientation->value];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/PageHeightOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/PageHeightOption.php
new file mode 100644
index 00000000..160ae39b
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/PageHeightOption.php
@@ -0,0 +1,17 @@
+height];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/PageSizeOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/PageSizeOption.php
new file mode 100644
index 00000000..61025935
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/PageSizeOption.php
@@ -0,0 +1,17 @@
+size];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/PageWidthOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/PageWidthOption.php
new file mode 100644
index 00000000..1cf72af4
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/PageWidthOption.php
@@ -0,0 +1,17 @@
+width];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/TitleOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/TitleOption.php
new file mode 100644
index 00000000..e4ac248b
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/TitleOption.php
@@ -0,0 +1,17 @@
+title];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/ExtraOption/UseXserverOption.php b/src/Backend/WkHtmlToPdf/ExtraOption/UseXserverOption.php
new file mode 100644
index 00000000..c5e9af5a
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/ExtraOption/UseXserverOption.php
@@ -0,0 +1,17 @@
+number];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/Options/GlobalOptions/DpiOption.php b/src/Backend/WkHtmlToPdf/Options/GlobalOptions/DpiOption.php
new file mode 100644
index 00000000..27542c90
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/Options/GlobalOptions/DpiOption.php
@@ -0,0 +1,15 @@
+dpi];
+ }
+}
diff --git a/src/Backend/WkHtmlToPdf/Options/GlobalOptions/GrayscaleOption.php b/src/Backend/WkHtmlToPdf/Options/GlobalOptions/GrayscaleOption.php
new file mode 100644
index 00000000..7093e0a7
--- /dev/null
+++ b/src/Backend/WkHtmlToPdf/Options/GlobalOptions/GrayscaleOption.php
@@ -0,0 +1,15 @@
+factory = $factory;
-
foreach ($options->extraOptions as $extraOption) {
if (!$extraOption instanceof ExtraOption) {
throw new \InvalidArgumentException("Invalid option type");
}
}
+ $this->factory = $factory;
$this->options = $options;
}
@@ -68,6 +67,7 @@ public function generateFromUri(UriInterface $uri): StreamInterface
$process = new Process(
command: [
$this->binary,
+ '--quiet',
...$this->compileOptions(),
$uri->toString(),
$outputStream->file->getPathname(),
@@ -75,6 +75,12 @@ public function generateFromUri(UriInterface $uri): StreamInterface
timeout: $this->timeout,
);
+ $process->run();
+
+ if (!$process->isSuccessful()) {
+ throw new ProcessFailedException($process);
+ }
+
return $outputStream;
}
@@ -86,10 +92,10 @@ private function compileOptions(): array
return array_reduce(
$this->options->extraOptions,
fn (array $carry, ExtraOption $extraOption) =>
- $this->options->pageOrientation !== null && $extraOption instanceof Orientation
+ $extraOption instanceof ExtraOption\OrientationOption && $this->options->pageOrientation !== null
? [
...$carry,
- ...(new Orientation($this->options->pageOrientation->value))->compile(),
+ ...ExtraOption\OrientationOption::fromPageOrientation($this->options->pageOrientation)->compile(),
]
: [
...$carry,