Comments (12)
I also got this error. I took the JSON string you pasted above tried it over at http://codebeautify.org/jsonviewer. I had to convert it to the below to get it to validate:
{
"destination": "C:\\\\Windows\\\\TEMP\\\\14b6e6edc209b6e731bdbc79976a9430438409ae.tmp",
"request": {
"uri": "C:\\\\Windows\\\\TEMP\\\\127ef8f78c335d9af694a9cef0423541dd17a256.html",
"method": "GET"
},
"orientation": "Portrait",
"format": "A3",
"zoomFactor": 1,
"allowParseCustomFooter": false,
"allowParseCustomHeader":false,
"border": "1cm",
"header": null,
"footer": null
}
Not sure yet if I can transfer this to the H2P library
EDIT: Had to update the backslashes to \\ to work with JSON.parse().
from h2p.
Hey @RaXaR , can you test setting the temp folder to a different one?
from h2p.
Hi Yeah, i tried using a folder inside the webroot but the same error appears:
Error while executing PhantomJS: "SyntaxError: JSON Parse error: Expected '}'"
To my eye it looks like an issue with escapeshellarg() being used in PhatomJS::transform() and then the parsing inside the converter.js at JSON.parse().
However, I can't figure out how to debug inside coverter.js so that I can see what strings it receives.
from h2p.
You can try using console.log()
inside converter.js and fetching its
result inside PHP, can you do that?
Daniel Pereira
2015-11-13 10:30 GMT-02:00 RaXaR [email protected]:
Hi Yeah, i tried using a folder inside the webroot but the same error
appears:Error while executing PhantomJS: "SyntaxError: JSON Parse error: Expected '}'"
To my eye it looks like an issue with escapeshellarg() being used in
PhatomJS::transform() and then the parsing inside the converter.js at
JSON.parse().However, I can't figure out how to debug inside coverter.js so that I can
see what strings it receives.—
Reply to this email directly or view it on GitHub
#14 (comment).
from h2p.
Nope, I don't know how to get the output of console.log to PHP?
from h2p.
Ok I resolved the parse error on windows with:
// /Converter/PhantomJS.php
protected function transform(Request $origin, $destination)
{
$request = self::fixRequestKeyNames($origin);
$args = array(
'destination' => $destination,
'request' => $request,
) + $this->options;
// If on Windows then do not use escapeshellarg();
$os = php_uname('s');
switch ($os) {
case 'Windows NT':
$json = json_encode($args);
$json = str_replace('"', '\"', $json);
$json = '"' . $json . '"';
$command = $this->getBinPath() . ' ' . $json;
break;
default:
$command = $this->getBinPath() . ' ' . escapeshellarg(json_encode($args));
}
$result = json_decode(trim(shell_exec($command)));
if (!$result->success) {
throw new Exception('Error while executing PhantomJS: "' . $result->response . '"');
}
return true;
}
I tested with:
$pdfDir = 'C:' . DIRECTORY_SEPARATOR . 'wamp' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR;
$converter = new PhantomJS();
$input = 'http://www.google.com/';
// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert($input, $pdfDir . 'page.pdf');
When I use new Tempfile() for input then I get:
Error while executing PhantomJS: "Unable to access the URI! (Make sure you're using a .html extension if you're trying to use a local file)"
Tested with:
$pdfDir = 'C:' . DIRECTORY_SEPARATOR . 'wamp' . DIRECTORY_SEPARATOR . 'www' . DIRECTORY_SEPARATOR;
$converter = new PhantomJS();
$input = new TempFile('<b>test string to pdf</b>', 'html'); // Make sure the 2nd parameter is 'html'
// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert($input, $pdfDir . 'page.pdf');
from h2p.
Note: Updated previous comment with a few fixes.
from h2p.
I had aa similar problem today on windows.
I had to use your updates transform() function and to had this fix:
$json = str_replace('C:', 'file:///c:', $json);
PhantomJS is not able to access fils on filesystem if url is not prefixed by file:///
from h2p.
I've just merged a PR that fixes that issues on Windows.
Can you guys test using master branch? (or dev-master for those using composer)
from h2p.
The PR fixed the issue with file://.
But not the original issue about the parse Error in windows.
from h2p.
I thought that the parsing error was directly related to the file:// issue - my bad.
from h2p.
No, on windows, the parsing error is related to the escapeshellarg function:
On Windows, escapeshellarg() instead removes percent signs, replaces double quotes with spaces and adds double quotes around the string.
So the command line is generated with an invalid json.
from h2p.
Related Issues (13)
- Error while executing PhantomJS: Unable to access the URI! HOT 7
- Error Executing a Test PDF HOT 15
- Handling with javascript errors HOT 2
- Erro na execução de um dos exemplos. HOT 3
- Class not found HOT 2
- Erro geração do pdf HOT 4
- Generating corrupted 0KB PDF HOT 9
- Seleção de DPI
- WriteHTML to PDF file has quality loss on images
- Temp file conversion does not work. HOT 5
- Support for more configuration parameters HOT 1
- Headers and footers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from h2p.