PdfTron PHP Optimizer

270 views
Skip to first unread message

Richard de Vries

unread,
Dec 2, 2014, 4:20:38 AM12/2/14
to pdfne...@googlegroups.com
I used the following instructions to build the PHP wrappers https://groups.google.com/d/msg/pdfnet-sdk/6a4PLMEjoQU/FykHay3HktIJ, unfortunately when running the Optimizer tests in de Samples directory I get the output listed below, the rest of the examples seem to run fine.

PDFNet is running in demo mode.
PHP Fatal error: No matching function for overloaded 'Optimizer_Optimize' in /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php on line 13859
PHP Stack trace:
PHP 1. {main}() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:0
PHP 2. Optimizer::Optimize() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:91
PHP 3. optimizer_optimize() /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php:13859

Fatal error: No matching function for overloaded 'Optimizer_Optimize' in /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php on line 13859

Call Stack:
0.0003 241152 1. {main}() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:0
0.1686 6659016 2. Optimizer::Optimize() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:91
0.1686 6659112 3. optimizer_optimize() /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php:13859

I used the following versions for compiling/running the examples, the operating system that was used is CentOS 6.6.

- cmake version 2.8.11.2
- gcc (GCC) 4.8.2 20140120
- PHP 5.5.18
- Swig 3.0.2

Does anyone know if I'm doing something wrong or is this a bug in PDFTron?

Ryan

unread,
Dec 2, 2014, 3:42:43 PM12/2/14
to pdfne...@googlegroups.com
Is this OptimizerTest.php file unmodified?

Or did you modify the PDFNetPHP.i file?

The Optimizer settings classes are nested classes, and so the PDFNetPHP.i file contains special information for the Optimizer settings.


Richard de Vries

unread,
Dec 3, 2014, 2:56:09 AM12/3/14
to pdfne...@googlegroups.com
I haven't touched the code yet. It's the unmodified version of OptimizerTest.php.

Op dinsdag 2 december 2014 21:42:43 UTC+1 schreef Ryan:

Ryan

unread,
Dec 3, 2014, 1:53:23 PM12/3/14
to pdfne...@googlegroups.com
It looks like the error is occuring no line 91 of the OptimizerTest.php file, which is the second call to Optimizer.Optimize.

This means the first call to Optimize() on line 54 worked?

It is very unclear how line 54 would work, but not line 91.

Can you post the code surrounding the line 13859 in PDFNetPHP.php file?



Richard de Vries

unread,
Dec 4, 2014, 4:52:40 AM12/4/14
to pdfne...@googlegroups.com
13834 class Optimizer {
13835         public $_cPtr=null;
13836         protected $_pData=array();
13837
13838         function __set($var,$value) {
13839                 if ($var === 'thisown') return swig_PDFNetPHP_alter_newobject($this->_cPtr,$value);
13840                 $this->_pData[$var] = $value;
13841         }
13842
13843         function __get($var) {
13844                 if ($var === 'thisown') return swig_PDFNetPHP_get_newobject($this->_cPtr);
13845                 return $this->_pData[$var];
13846         }
13847
13848         function __isset($var) {
13849                 if ($var === 'thisown') return true;
13850                 return array_key_exists($var, $this->_pData);
13851         }
13852         function __construct($h) {
13853                 $this->_cPtr=$h;
13854         }
13855
13856         static function Optimize($doc,$settings=null) {
13857                 switch (func_num_args()) {
13858                 case 1: Optimizer_Optimize($doc); break;
13859                 default: Optimizer_Optimize($doc,$settings);
13860                 }
13861         }
13862 }

You're right it doesn't work if you pass the settings parameter. If you omit that value it does work.

Op woensdag 3 december 2014 19:53:23 UTC+1 schreef Ryan:

Ryan

unread,
Dec 4, 2014, 2:59:14 PM12/4/14
to pdfne...@googlegroups.com
It definitely looks to be a problem with explictly declared OptimizerSettings class in the PDFNetPHP.i file. I suspect the latest SWIG 3.02 that you are using is not generating something compatible with our .i file anymore.

Can you please try the following.
1. Modify the ConverTest.php so that it uses a settings object. For example 

// Convert PDF document to HTML
echo(nl2br("Converting PDF to HTML\n"));
$outputFile = $outputPath."pdf2html";
$settings
= new HTMLOutputOptions()
;
Convert::ToHtml($inputPath."newsletter.pdf", $outputFile, $settings);
echo(nl2br("Saved ".$outputFile."\n"));

I suspect that this too will fail with the same error.

2. Rebuild the wrapper, but using SWIG 2.0.12. I think this will fix the issue.

I see this comment on the SWIG 3.0.0 release announcement, which makes me suspicious.

  • Nested class support added. This has been taken full advantage of in
    Java and C#. Other languages can use the nested classes, but require
    further work for a more natural integration into the target language.
    We urge folk knowledgeable in the other target languages to step
    forward and help with this effort.

Richard de Vries

unread,
Dec 8, 2014, 9:39:41 AM12/8/14
to pdfne...@googlegroups.com

I tried using swig 2.0.12 to rebuild the wrappers but I'm still getting the same error. But it does seem te be on a different line this time. Here's the build output and the fatal error when running the Optimizer test.

Modifying the ConvertTest.php also doesn't seem to make a difference.


cmake28 -D BUILD_PDFNetPHP=ON ..
-- The CXX compiler identification is GNU 4.8.2
-- Check for working CXX compiler: /opt/rh/devtoolset-2/root/usr/bin/c++
-- Check for working CXX compiler: /opt/rh/devtoolset-2/root/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found SWIG: /usr/local/bin/swig (found version "2.0.12")
-- Using SWIG 2.0.12
-- Using PHP include directories: -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
-- Generating sources for PHP bindings using swig...
-- Generating sources for PHP bindings using swig... OK
-- Configuring done
-- Generating done
-- Build files have been written to: /home/unitrust/wrappers_build/PDFNetWrappers/Build

make
Scanning dependencies of target PDFNetPHP
[100%] Building CXX object PDFNetPHP/CMakeFiles/PDFNetPHP.dir/PDFNetPHP.cpp.o
Linking CXX shared module ../lib/PDFNetPHP.so
[100%] Built target PDFNetPHP

make install
[100%] Built target PDFNetPHP
Install the project...
-- Install configuration: ""
-- Installing: /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php
-- Installing: /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so
-- Removed runtime path from "/home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.so"

Running the optimizer test:


PDFNet is running in demo mode.
PHP Fatal error:  No matching function for overloaded 'Optimizer_Optimize' in /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php on line 13865

PHP Stack trace:
PHP   1. {main}() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:0
PHP   2. Optimizer::Optimize() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:91
PHP   3. optimizer_optimize() /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php:13865

Fatal error: No matching function for overloaded 'Optimizer_Optimize' in /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php on line 13865

Call Stack:
    0.0004     241152   1. {main}() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:0
    0.1688    6666016   2. Optimizer::Optimize() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/OptimizerTest/PHP/OptimizerTest.php:91
    0.1689    6666112   3. optimizer_optimize() /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php:13865

Op donderdag 4 december 2014 20:59:14 UTC+1 schreef Ryan:

Ryan

unread,
Dec 8, 2014, 2:51:42 PM12/8/14
to pdfne...@googlegroups.com

Modifying the ConvertTest.php also doesn't seem to make a difference.



You mean you modified the call to Convert.ToHtml to use the settings object? Did that work, or did you get the same error as with Optimizer?

Also, are you 32 or 64bit OS? And is your PHP process 32 or 64bit?

Richard de Vries

unread,
Dec 10, 2014, 3:55:07 AM12/10/14
to pdfne...@googlegroups.com
Using the Convert::ToHtml function with the options results in the same error:

PHP Fatal error:  No matching function for overloaded 'Convert_ToHtml' in /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php on line 11297
PHP Stack trace:
PHP   1. {main}() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/ConvertTest/PHP/ConvertTest.php:0
PHP   2. main() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/ConvertTest/PHP/ConvertTest.php:124
PHP   3. ConvertSpecificFormats() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/ConvertTest/PHP/ConvertTest.php:119
PHP   4. Convert::ToHtml() /home/unitrust/wrappers_build/PDFNetWrappers/Samples/ConvertTest/PHP/ConvertTest.php:98
PHP   5. convert_tohtml() /home/unitrust/wrappers_build/PDFNetWrappers/PDFNetC/Lib/PDFNetPHP.php:11297

It's the 64bit version of CentOS and the PHP process also runs on 64bit.


Op maandag 8 december 2014 20:51:42 UTC+1 schreef Ryan:

Iwan Luijks

unread,
Mar 20, 2015, 4:10:30 PM3/20/15
to pdfne...@googlegroups.com
Is there any resolution for this yet?



Op woensdag 10 december 2014 09:55:07 UTC+1 schreef Richard de Vries:

Thomas Allen

unread,
Nov 16, 2016, 3:59:43 PM11/16/16
to PDFTron PDFNet SDK
I know this is an old thread but I came across it while searching how to build the PHP wrappers on Ubuntu 16.04 and PHP 5.6. (SWIG is not yet compatible with PHP 7 so that's not yet an option).

I was able to build the PHP wrappers using Swig 2, which I had to manually download and install from here: http://www.linuxfromscratch.org/blfs/view/7.5/general/swig.html

I also had to completely remove the Build/ directory. I originally tried building the wrappers using Swig 3, and rebuilding the wrappers with Swig 2 didn't work until I removed the Build/ directory and started over from scratch.
Reply all
Reply to author
Forward
0 new messages