Skip to content
This repository was archived by the owner on Apr 14, 2024. It is now read-only.

Commit cfc099e

Browse files
author
Julien Neuhart
committed
now allowing to set paper size and orientation for office conversions
1 parent 0536b30 commit cfc099e

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ before_install:
1010
- sudo mv ./orbit /usr/local/bin && chmod +x /usr/local/bin/orbit
1111

1212
script:
13-
- orbit run lint
13+
- orbit run lint up tests

src/OfficeRequest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ final class OfficeRequest extends Request implements GotenbergRequestInterface
77
/** @var Document[] */
88
private $files;
99

10+
/** @var float|null */
11+
private $paperWidth;
12+
13+
/** @var float|null */
14+
private $paperHeight;
15+
16+
/** @var bool */
17+
private $landscape;
18+
1019
/**
1120
* OfficeRequest constructor.
1221
* @param Document[] $files
@@ -34,6 +43,13 @@ public function getFormValues(): array
3443
if (!empty($this->webhookURL)) {
3544
$values[self::WEBHOOK_URL] = $this->webhookURL;
3645
}
46+
if (!is_null($this->paperWidth)) {
47+
$values[self::PAPER_WIDTH] = $this->paperWidth;
48+
}
49+
if (!is_null($this->paperHeight)) {
50+
$values[self::PAPER_HEIGHT] = $this->paperHeight;
51+
}
52+
$values[self::LANDSCAPE] = $this->landscape;
3753
return $values;
3854
}
3955

@@ -48,4 +64,25 @@ public function getFormFiles(): array
4864
}
4965
return $files;
5066
}
67+
68+
/**
69+
* @param float[] $paperSize
70+
* @throws RequestException
71+
*/
72+
public function setPaperSize(array $paperSize): void
73+
{
74+
if (count($paperSize) !== 2) {
75+
throw new RequestException('Wrong paper size.');
76+
}
77+
$this->paperWidth = $paperSize[0];
78+
$this->paperHeight = $paperSize[1];
79+
}
80+
81+
/**
82+
* @param bool $landscape
83+
*/
84+
public function setLandscape(bool $landscape): void
85+
{
86+
$this->landscape = $landscape;
87+
}
5188
}

tests/ClientTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ public function createMarkdownRequest(): MarkdownRequest
8585

8686
/**
8787
* @return OfficeRequest
88+
* @throws RequestException
8889
*/
8990
public function createOfficeRequest(): OfficeRequest
9091
{
9192
$files = [
9293
DocumentFactory::makeFromPath('document.docx', __DIR__ . '/assets/office/document.docx'),
9394
];
9495
$request = new OfficeRequest($files);
96+
$request->setPaperSize(Request::A4);
9597
return $request;
9698
}
9799

0 commit comments

Comments
 (0)