Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 220e5d8

Browse files
update pdf converter code
1 parent 7aaaf96 commit 220e5d8

File tree

4 files changed

+452
-9
lines changed

4 files changed

+452
-9
lines changed

‎app/Http/Controllers/DocumentController.php‎

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace App\Http\Controllers;
44

55

6+
use Dompdf\Dompdf;
67
use PhpOffice\PhpWord\IOFactory;
8+
use PhpOffice\PhpWord\PhpWord;
79
use PhpOffice\PhpWord\Settings;
10+
use PhpOffice\PhpWord\Shared\Html;
811
use PhpOffice\PhpWord\TemplateProcessor;
912
use Vish4395\LaravelFileViewer\LaravelFileViewer;
1013

@@ -15,20 +18,20 @@ public function index()
1518
{
1619
//get variables from docx file
1720
$filepath = storage_path('app/public/documents/test.docx');
18-
$templateProcessor = new TemplateProcessor($filepath);
21+
// $templateProcessor = new TemplateProcessor($filepath);
1922
// $variables = $templateProcessor->getVariables();
2023
// foreach ($variables as $variable){
2124
// dd($variable);
2225
// }
2326

2427
//set value to variable
25-
$templateProcessor->setValues(array('name' => 'John Doe', 'email' => 'John@gmail.com','phone' => '01928472474'));
28+
// $templateProcessor->setValues(array('name' => 'John Doe', 'email' => 'John@gmail.com','phone' => '01928472474'));
2629

2730
//save the updated file
28-
$updatepath = storage_path('app/public/documents/testUpdate.docx');
29-
$templateProcessor->saveAs($updatepath);
31+
// $updatepath = storage_path('app/public/documents/testUpdate.docx');
32+
// $templateProcessor->saveAs($updatepath);
3033

31-
//convert docx to pdf
34+
//convert docx to pdf without original style
3235
$pdfpath = storage_path('app/public/documents/test.pdf');
3336

3437
$domPdfPath = base_path('vendor/dompdf/dompdf');
@@ -38,6 +41,32 @@ public function index()
3841
$PDFWriter = IOFactory::createWriter($Content,'PDF');
3942
$PDFWriter->save($pdfpath);
4043

44+
45+
46+
// Save the document as HTML
47+
// $filepath = storage_path('app/public/documents/test.docx');
48+
// Settings::setOutputEscapingEnabled(true);
49+
// $phpWord = IOFactory::load($filepath);
50+
// $xmlWriter = IOFactory::createWriter($phpWord, 'HTML');
51+
// $htmlFilePath = storage_path('app/public/documents/' . 'test' . '.html');
52+
// $xmlWriter->save($htmlFilePath);
53+
54+
// Convert the HTML to PDF using DOMPDF
55+
// $dompdf = new Dompdf();
56+
// $html = file_get_contents($htmlFilePath);
57+
// $dompdf->loadHtml($html);
58+
// $dompdf->setPaper('A4', 'portrait');
59+
// $dompdf->render();
60+
//
61+
// $pdfpath = storage_path('app/public/documents/test.pdf');
62+
// $pdf_output = $dompdf->output();
63+
// file_put_contents($pdfpath, $pdf_output);
64+
65+
// Delete the temporary files
66+
// unlink($htmlFilePath);
67+
68+
69+
4170
return redirect('/');
4271
}
4372

‎composer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"require": {
88
"php": "^8.1",
99
"dompdf/dompdf": "^2.0",
10+
"google/apiclient": "^2.0",
1011
"guzzlehttp/guzzle": "^7.2",
1112
"laravel/framework": "^10.0",
1213
"laravel/sanctum": "^3.2",
1314
"laravel/tinker": "^2.8",
1415
"phpoffice/phpword": "^1.0",
15-
"vish4395/laravel-file-viewer": "^1.0",
16-
"google/apiclient": "^2.0"
16+
"vish4395/laravel-file-viewer": "^1.0"
1717
},
1818
"require-dev": {
1919
"fakerphp/faker": "^1.9.1",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /