Forum


Replies: 3   Views: 222
"native" word to pdf conversion (also word to html conversion)
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by bre-europe  · 12-04-2019 - 14:32

We use phpfocx v9 and would like to evaluate the possibilities of native PDF conversion (compared to one of the othe roptions).

The code

$docx = new TransformDocAdvNative();
$docx->transformDocument($source, $dest);

produces a lot of PHP notices, e.g.

Undefined property: Phpdocx\Transform\TransformDocAdvHTMLTCPDFPlugin::$extraClasses  ... TransformDocAdvHTMLPlugin.php, line 184
Undefined property: Phpdocx\Transform\TransformDocAdvPDF::$complexField ... TransformDocAdvPDF.php, line 2148

The first of above happens in TransformDocAdvHTMLPlugin.php, around line 184:

public function getExtraClass()
{
    return $this->extraClasses[$tag];
}

Our IDE says "Field extraClasses not found". Also I am wondering where $tag should come from, as it is not a function parameter.

Can you help?

Posted by admin  · 12-04-2019 - 18:54

Edited by admin · 12-04-2019 - 19:27

Hello,

You are right, this method:

public function getExtraClass()
{
  return $this->extraClasses[$tag];
}

should be:

public function getExtraClass($tag)
{
  if (isset($this->extraClasses[$tag])) {
    return $this->extraClasses[$tag];
  }
}

to avoid that PHP notice. This method is only needed when adding extra classes to tags from external resources, so this missing parameter only affects when trying to overwrite the default classes, but the class displays the notices when trying to access it.

To remove the second notice, please add to the TransformDocAdvPDF class this new property:

/**
 *
 * @access protected
 * @var array
 */
protected $complexField = null;

before

/**
 *
 * @access protected
 * @var array
 */
protected $css = array();

Please update both classes with the previous changes. We have updated all phpdocx packages with these same changes.

Regards.

Posted by bre-europe  · 16-04-2019 - 13:54

Thanks, that helped regarding the issues mentioned earlier, but there are more notices. Most of them in TransformDocAdvPDF.php, but also in TCPDF_lib.php.

Examples:

  • Undefined index: docx_5cb5dc6c27a226_07553361, paragraph_Textkrper [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvPDF.php, line 2018]
    

 

  • Undefined index: word/header1.xml [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvPDF.php, line 2214]
    
  • Undefined index: word/header2.xml [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvPDF.php, line 2214]
    
  • Undefined index: word/footer1.xml [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvPDF.php, line 2219]
    
  • Undefined index: docx_5cb5dc6d21a7a1_40713843, character_Hyperlink [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Transform/TransformDocAdvPDF.php, line 2152]
    
  • Undefined offset: 0 [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Libs/TCPDF_lib.php, line 43855]
    
  • Undefined offset: -1 [/var/www/html/newton-test/newton/core/vendor/phpdocx/Classes/Phpdocx/Libs/TCPDF_lib.php, line 45234]
    

The line numbers in TransformDocAdvPDF.php are according to the patched version. I am afraid there are more patches needed. For the first example above, line 2018 is:

$this->css[$nodeClass] .= $this->addPprStyles($childNode);

It seems that $this->css[$nodeClass] is not initialized, which leads to the notice.

How can we proceed from this?

 

Posted by admin  · 16-04-2019 - 17:20

Edited by admin · 16-04-2019 - 18:01

Hello,

We move them to the dev team. We recommend you to hide PHP notices to avoid them when using that method, if some attribute or content is not supported it may throw a PHP notice; it seems you are trying to transform a document with headers and footers that are not supported yet by the native method conversion. If your document is using a not supported content by the native method (https://www.phpdocx.com/documentation/conversion-plugin/preparing-the-templates-for-its-conversion Supported OOXML tags and attributes when using the native method section), we recommend using the conversion plugin based on LibreOffice.

Regards.