Skip to content

Commit

Permalink
Merge pull request #1 from omaralalwi/add-new-examples-for-store-in-s3
Browse files Browse the repository at this point in the history
add new examples for store in s3
  • Loading branch information
omaralalwi authored May 31, 2024
2 parents 4afa8e5 + 2ab803e commit 320988c
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 9,789 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

GPDF_STORAGE_DRIVER=s3

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

VITE_APP_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ yarn-error.log
/.fleet
/.idea
/.vscode
composer.lock


37 changes: 32 additions & 5 deletions app/Http/Controllers/GpdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
use Illuminate\Support\Facades\Config;
use Omaralalwi\Gpdf\Gpdf;
use Omaralalwi\Gpdf\Facade\Gpdf as GpdfFacAde;
use Omaralalwi\Gpdf\Enums\{GpdfDefaultSettings as GpdfDefault, GpdfSettingKeys as GpdfSet, GpdfDefaultSupportedFonts};
use Omaralalwi\Gpdf\Enums\{GpdfDefaultSettings as GpdfDefault,
GpdfSettingKeys as GpdfSet,
GpdfDefaultSupportedFonts,
GpdfStorageDrivers};
use Illuminate\Support\Facades\Log;

class GpdfController extends Controller
{
Expand Down Expand Up @@ -82,15 +86,38 @@ public function generateAndStream()
public function generateAndStore()
{
$data = $this->getDynamicParams();
$html = view('pdf.example-2',$data)->render();
$gpdf = app(Gpdf::class);
$file = $gpdf->generateWithStore($html, null, 'test-store-pdf-fle', true, false); // we used default storage path /public/downloads/pdfs
$fileUrl = $file['ObjectURL'];

return $fileUrl; // return file url as string to store it to db or do any action
}

public function generateAndStoreToS3()
{
$data = $this->getDynamicParams();
$html = view('pdf.example-2',$data)->render();
$gpdf = app(Gpdf::class);
$file = $gpdf->generateWithStoreToS3($html, null, 'test-store-pdf-fle', true, true);

return $file['ObjectURL']; // return file url as string
}

public function generateAndStoreMultiplePages()
{
$data = $this->getDynamicParams();

// generate from many html pages in same pdf file
$html = collect(['pdf.example-1', 'pdf.example-2', 'pdf.example-3'])
->map(fn($view) => view($view, $data)->render())
->implode('');

$gpdf = app(Gpdf::class);
$storePath = storage_path('/app/downloads/users/');
$gpdf->generateWithStore($html, $storePath, 'test-store-pdf-fle'); // file name optionals
$file = $gpdf->generateWithStore($html, null, 'test-store-pdf-fle'); // file name optionals
$fileUrl = $file['ObjectURL'];

$pdfFile = $gpdf->generate($html); // optional
return response($pdfFile, 200, ['Content-Type' => 'application/pdf']);
Log::info($fileUrl);
}

public function generatePdfWithArabicContent()
Expand Down
Binary file not shown.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"laravel/framework": "^11.0",
"laravel/passport": "^12.0",
"laravel/tinker": "^2.9",
"nwidart/laravel-modules": "^11.0",
"omaralalwi/gpdf": "^1.0"
"omaralalwi/gpdf": "^1.0.1"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand Down
Loading

0 comments on commit 320988c

Please sign in to comment.