Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
->ignoreErrorsOnPackage('twig/twig', [
ErrorType::DEV_DEPENDENCY_IN_PROD,
])
->ignoreErrorsOnPackage('symfony/security-core', [
ErrorType::DEV_DEPENDENCY_IN_PROD,
])
;

if (\PHP_VERSION_ID < 80200) { // TODO: Requires PHP >= 8.2
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"symfony/http-client": "^6.4 || ^7.0",
"symfony/monolog-bundle": "^3.10",
"symfony/routing": "^6.4 || ^7.0",
"symfony/security-core": "^6.4 || ^7.0",
"symfony/stopwatch": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
"symfony/var-dumper": "^6.4 || ^7.0",
Expand All @@ -68,6 +69,7 @@
"symfony/twig-bundle": "Allows you to use Twig to render templates into PDF.",
"monolog/monolog": "Enables logging througout the generating process.",
"async-aws/s3": "Upload any file to aws s3 compatible endpoints supporting multi part upload without memory overhead.",
"league/flysystem-bundle": "Upload any file using this filesystem abstraction package."
"league/flysystem-bundle": "Upload any file using this filesystem abstraction package.",
"symfony/security-core": "Allows you to use asUser method to generate with CLI required an authentication"
}
}
4 changes: 4 additions & 0 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### generateDocumentOutline(bool $bool)
Expand Down
4 changes: 4 additions & 0 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### generateDocumentOutline(bool $bool)
Expand Down
4 changes: 4 additions & 0 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### generateDocumentOutline(bool $bool)
Expand Down
93 changes: 93 additions & 0 deletions docs/pdf/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
[cookies](#cookies)
[setCookie](#setCookie)
[addCookies](#addCookies)
[forwardCookie](#forwardCookie)
[forwardAuthentication](#forwardAuthentication)
[asUser](#asUser)
[userAgent](#userAgent)
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
Expand Down Expand Up @@ -872,6 +875,96 @@ class YourController
}
```

### forwardCookie

If you want to forward existing cookie from the current request.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->forwardCookie('my_cookie')
->generate()
->stream()
;
}
}
```

### forwardAuthentication

If you want to forward the authentication cookie from the current request.
Can be useful to generate a PDF from restricted route.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->url()
->route('auth_route')
->forwardAuthentication()
->generate()
->stream()
;
}
}
```

### asUser

If you want to generate a PDF for a restricted route in a CLI context.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

#[AsCommand(name: 'app:create-pdf', description: 'Create pdf')]
final class CreatePdf extends Command
{
public function __construct(
private readonly GotenbergPdfInterface $gotenberg,
private readonly UserProviderInterface $userProvider,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userProvider->loadUserByIdentifier('john_doe');

return $this->gotenberg
->url()
->route('auth_route')
->asUser($user)
->processor(new FileProcessor(new Filesystem(), dirname(__DIR__).'/../var/pdf'))
->generate()
->process()
;

$output->writeln('PDF generated');

return Command::SUCCESS;
}
}
```

### userAgent()

default: `None`
Expand Down
4 changes: 4 additions & 0 deletions docs/screenshot/builders_api/HtmlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### clip(bool $bool)
Expand Down
4 changes: 4 additions & 0 deletions docs/screenshot/builders_api/MarkdownScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### clip(bool $bool)
Expand Down
4 changes: 4 additions & 0 deletions docs/screenshot/builders_api/UrlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ Sets the webhook for cases of success.<br />Optionally sets a custom HTTP method
### addCookies(array $cookies)
Add cookies to store in the Chromium cookie jar.<br />

### asUser(Symfony\Component\Security\Core\User\UserInterface $user, string $firewallName)
For CLI generation usage.

### cookies(array $cookies)
### forwardAuthentication()
### forwardCookie(string $name)
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie)
### clip(bool $bool)
Expand Down
113 changes: 112 additions & 1 deletion docs/screenshot/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
[cookies](#cookies)
[setCookie](#setCookie)
[addCookies](#addCookies)
[forwardCookie](#forwardCookie)
[forwardAuthentication](#forwardAuthentication)
[asUser](#asUser)
[userAgent](#userAgent)
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
Expand Down Expand Up @@ -217,7 +220,7 @@ class YourController
],
[
'url' => 'http://example.com/url/to/file',
'extraHttpHeaders' =>
'extraHttpHeaders' =>
[
'MyHeaderOne' => 'MyValue',
'MyHeaderTwo' => 'MyValue',
Expand Down Expand Up @@ -283,6 +286,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->waitDelay('5s')
->generate()
->stream()
Expand All @@ -309,6 +315,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->waitForExpression("window.globalVar === 'ready'")
->generate()
->stream()
Expand Down Expand Up @@ -339,6 +348,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->emulatedMediaType(EmulatedMediaType::Screen)
->generate()
->stream()
Expand Down Expand Up @@ -366,6 +378,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->cookies([[
'name' => 'my_cookie',
'value' => 'symfony',
Expand Down Expand Up @@ -400,6 +415,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->setCookie([
'name' => 'my_cookie',
'value' => 'symfony',
Expand Down Expand Up @@ -431,6 +449,9 @@ class YourController
{
return $gotenberg
->html()
->content('twig_simple_pdf.html.twig', [
'my_var' => 'value'
])
->addCookies([[
'name' => 'my_cookie',
'value' => 'symfony',
Expand All @@ -446,6 +467,96 @@ class YourController
}
```

### forwardCookie

If you want to forward existing cookie from the current request.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->forwardCookie('my_cookie')
->generate()
->stream()
;
}
}
```

### forwardAuthentication

If you want to forward the authentication cookie from the current request.
Can be useful to generate a screenshot from restricted route.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg
->url()
->route('auth_route')
->forwardAuthentication()
->generate()
->stream()
;
}
}
```

### asUser

If you want to generate a screenshot for a restricted route in a CLI context.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

#[AsCommand(name: 'app:create-pdf', description: 'Create pdf')]
final class CreatePdf extends Command
{
public function __construct(
private readonly GotenbergScreenshotInterface $gotenberg,
private readonly UserProviderInterface $userProvider,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userProvider->loadUserByIdentifier('john_doe');

return $this->gotenberg
->url()
->route('auth_route')
->asUser($user)
->processor(new FileProcessor(new Filesystem(), dirname(__DIR__).'/../var/screenshot'))
->generate()
->process()
;

$output->writeln('PDF generated');

return Command::SUCCESS;
}
}
```

### userAgent()

default: `None`
Expand Down
Loading