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

problem converting docx to pdf #282

Closed
Max75010 opened this issue Jun 17, 2014 · 14 comments
Closed

problem converting docx to pdf #282

Max75010 opened this issue Jun 17, 2014 · 14 comments

Comments

@Max75010
Copy link

Hi

i'm having a problem converting a docx generated by phpword into pdf with mpdf. (you can see issue #210).

Here is the code I'm using :

$phpWord = \PhpOffice\PhpWord\IOFactory::load( UPLOADS_INC . $filename );
$pdfWriter = \PhpOffice\PhpWord\IOFactory::createWriter( $phpWord, 'PDF' );
$pdfWriter->save( UPLOADS_INC . $pdfFilename );

And I keep having this error :

PHP Catchable fatal error: Argument 2 passed to DOMXPath::query() must be an instance of DOMNode, null given, called in /var/www/xxx/PhpWord/Reader/Word2007.php on line 145 and defined in /var/www/xxx/PhpWord/Shared/XMLReader.php on line 99, referer: XXX

Am I doing something wrong ?
I tried to convert a docx that hasn't been generated by phpword and I still have the error.

@ivanlanin ivanlanin added this to the 0.12.0 milestone Jun 17, 2014
@ivanlanin
Copy link
Contributor

Hi @Max75010. I have some questions:

  1. Can you open the original file (UPLOADS_INC . $filename) with text processing application (MS Word, Pages, OpenOffice)?
  2. Which PHPWord version were you using? You can see CHANGELOG.md
  3. Which platform were you using to run PHPWord? (OS, webserver, PHP)

@Max75010
Copy link
Author

Thanks for the reply.

I'm using version 0.11.1 - 2 June 2014.
I can open the original file without any problem on my computer and I'm using phpword on a ubuntu 10.04.4 / apache 2.2 / php 5.3.2

@Progi1984
Copy link
Member

@Max75010 May be you have a specificity in your DOCX, not working with PHPWord. Could you add a link to your DOCX for tests ?

@Max75010
Copy link
Author

Thanks for you replies.

Here is a wetransfer to the file (sorry I can't put the direct link but I'm using exactly the same docx)

http:https://we.tl/Qd52tNSZZY

I tried to use a new docx with only a few lines of text, and not generated by phpword, I still have the problem.

@ivanlanin
Copy link
Contributor

I'm able to run your script with the doc that you sent. This issue probably arise for some system settings. Can you run samples/index.php using CLI or webbrowser to check the requirements? I suspect that either the ZipArchive or temp folder caused this problem.

@Max75010
Copy link
Author

Requirement check:

PHP 5.3.0 ... passed
PHP extension XML ... passed
PHP extension ZipArchive (optional) ... passed
PHP extension GD (optional) ... passed
PHP extension XMLWriter (optional) ... passed
PHP extension XSL (optional) ... passed

I'm having the problem on the first line : $phpWord = \PhpOffice\PhpWord\IOFactory::load( UPLOADS_INC . $filename );

I tried to check if the path was the right path (with is_file()) and there is no problem with it. I also tried to put 777 authorizations on the directory where I put the docx and the files inside but it doesn't change anything.

@ivanlanin
Copy link
Contributor

Sorry. I forgot that the temp folder check is not yet available in 0.11. See #238. Please create a script with something like this:

<?php
var_dump(is_writable(sys_get_temp_dir()));

The result should be true. If it's indeed true, we need to find other possible causes. Thanks.

@Max75010
Copy link
Author

unfortunately, the result is bool(true).

@Progi1984
Copy link
Member

@Max75010
Copy link
Author

I checked and it returns a DOMDocument object ..

@Progi1984
Copy link
Member

Could you test with this code here : https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Shared/XMLReader.php#L99

return $this->xpath->query($path, $contextNode);

replaced by

if (is_null($contextNode)) {
    return $this->xpath->query($path);
} else {
    return $this->xpath->query($path, $contextNode);
}

@Max75010
Copy link
Author

Now it works ! Thanks a lot !

Progi1984 added a commit that referenced this issue Jun 17, 2014
PHP Catchable fatal error: Argument 2 passed to DOMXPath::query() must be an instance of DOMNode, null given, called in /var/www/xxx/PhpWord/Reader/Word2007.php on line 145 and defined in /var/www/xxx/PhpWord/Shared/XMLReader.php on line 99, referer: XXX
@Progi1984 Progi1984 self-assigned this Jun 17, 2014
@Progi1984
Copy link
Member

Perfect. Bugfix commited in the branch develop.

@ivanlanin
Copy link
Contributor

👍

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

No branches or pull requests

3 participants