Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert pdf to Word Document #2560

Open
richardsonoge opened this issue Jan 31, 2024 · 0 comments
Open

Convert pdf to Word Document #2560

richardsonoge opened this issue Jan 31, 2024 · 0 comments

Comments

@richardsonoge
Copy link

I need to convert from PDF to Word(docx, doc and other word files too,,,), I proceeded with this code but it gave me a big error. I'll give you below my code and the errors I received in this Library. I would like to say is there any way you know of that I could use to convert the PDF to Word file efficiently? Any way you think I could use without going through APIs please tell me!

<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpWord\IOFactory as WordIOFactory;

/*********************** Convert a DOCM file to PDF ************************/

    // To enable pdf exporting with phpword
    class_alias( \Dompdf\Dompdf::class, 'DOMPDF');

    // Assuming dompdf_config.inc.php is in the same directory
    use \PhpOffice\PhpWord\Settings;
    Settings::setPdfRenderer( Settings::PDF_RENDERER_DOMPDF, __DIR__ );

    $phpWord = WordIOFactory::load('documents/ar-11_unlocked.pdf', 'PDF');

    $objWriter = WordIOFactory::createWriter($phpWord, 'Word2007');
    $objWriter->save('convert/test.pdf');

/*********************** END Convert a DOCM file to PDF ************************/

Here the errors that I get:

[30-Jan-2024 19:05:48 America/New_York] PHP Fatal error:  Uncaught PhpOffice\PhpWord\Exception\Exception: "PDF" is not a valid Reader. in /opt/lampp/htdocs/filenigma/vendor/phpoffice/phpword/src/PhpWord/IOFactory.php:73
Stack trace:
#0 /opt/lampp/htdocs/filenigma/vendor/phpoffice/phpword/src/PhpWord/IOFactory.php(54): PhpOffice\PhpWord\IOFactory::createObject()
#1 /opt/lampp/htdocs/filenigma/vendor/phpoffice/phpword/src/PhpWord/IOFactory.php(87): PhpOffice\PhpWord\IOFactory::createReader()
#2 /opt/lampp/htdocs/filenigma/index.php(59): PhpOffice\PhpWord\IOFactory::load()
#3 {main}
  thrown in /opt/lampp/htdocs/filenigma/vendor/phpoffice/phpword/src/PhpWord/IOFactory.php on line 73

PLEASE! Any help will be appreciated and don't hesitate to comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant