KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Implementing PhantomJsCloud in export package #570

Open Alex Chartier opened this topic on on Dec 20, 2018 - 22 comments

Alex Chartier commented on Dec 20, 2018

Due to ongoing frustration getting a local version of phantomjs to work on a 64 bit GNU/Unix system I have resorted to developing an integration to the offsite PhantomJsCloud service to render the pdf for me. I have made a rudimentary implementation which is limited to changes in only one php file. The file is libraries/koolreports/packages/export/Handler.php

Along with the changes suggested in my other post on Handler.php this implementation works with the limited testing I have done.

Are you (KoolReport) interested in having the changes for implementation? If so I can email them to you.

KoolReport commented on Dec 20, 2018

Hi Alex,

It is a good idea. I would like to ask if you know: Is PhantomJsCloud able to work with access-restricted site. For example, if your site is at localhost or inside intranet which phantomjs has no way to access your resources: js, css, image?

Does it support uploading required resources to phantomjscloud service together with content?

Alex Chartier commented on Dec 20, 2018

Those are very good questions. I doubt they would work with access restricted site, localhost or intranet.

How would you load them, I imagine we would have to read all the css and script and include it inline? It is something I can test. The logic is already there to capture the script and link references so it would be easy enough to read the files in and include them inline.

if you would like me to give it a try I can. The test I am using uses only a couple of css files and a few js files so it wouldn't be a huge issue. Have to be tomorrow though.

KoolReport commented on Dec 20, 2018

Yes, we need to find a way to capture the images on page as well. Another issue with css is that we need to capture the font going along with css. For example, bootstrap has font files or fontawesome has their own woff2 file.

Alex Chartier commented on Dec 20, 2018

Well, perhaps this isn't going to work then unless files can be staged in the cloud somewhere but I am not sure this is really a good option. For my purposes I only need a table represented but I can see how grphics could be a much bigger issue.

KoolReport commented on Dec 20, 2018

Actually we are very interested in this idea since we also have much trouble in supporting customers to setup the phantomjs. Even in some cases, we need to ask for customers' server access to find out what happens that phantomjs does not work in their server (we dont like and customers do not like too :( ). So we have thought of setting up a online service like PhantomjsCloud to reduce the burden of installation. Everything just work! But those above issues keep us look for the solutions. Our ambition is to make online services work with all cases whether the site is offline or online. Also we want to use Chrome Headless instead of PhantomJs. PhantomJs is still great but project has stopped and Chrome is better in term of memory usage and rendering.

Alex Chartier commented on Dec 20, 2018

True, but finding a chrome solution for shared linux servers is problematic.

i can give you want I have if you want it. It is not a lot of extra code.

KoolReport commented on Dec 20, 2018

Yes, please send me the code for using phantomjscloud, I would like to see and if possible making some test too.

Alex Chartier commented on Dec 20, 2018

Sent to you by email.

KoolReport commented on Dec 20, 2018

I got it.

Alex Chartier commented on Dec 21, 2018

You will also need the pdf settings from the export to make sense of the payload options in the runPhantonJsCloud function. Note: this was just a hack to prove it would work, I would use the existing pdf options and map them to the payload at runtime.

$choices = new EventPrintChoices();
$choices->run()->export('EventPrintChoices.pdf')
			->settings($settings)
			->pdf([
				"phantomJsCloud"=>[
					"key"=>"a-demo-key-with-low-quota-per-ip-address",
					"pdfOptions"=>[
						"border"=>null,
						"footer"=>[
							"firstPage"=>null,
							"height"=>"1cm",
							"lastPage"=>null,
							"onePage"=>null,
							"repeating"=>"%pageNum/%numPages%"
							],
						"format"=>"letter",
						"header"=>null,
						"height"=>null,
						"orientation"=>"landscape",
						"width"=>null,
					],
				],
			 	"format"=>"letter", 
			 	"orientation"=>"landscape"
			 	]
			 )
			->toBrowser("choices.pdf");

Alex Chartier commented on Jan 1, 2019

This solution is working nicely for me. It turns out phantomJsCloud is using headless chrome as the rendering engine so the future use seems good.

If anyone else happens upon this thread the settings above will not work with off-the-shelf KoolReports. Modifications are needed to the Handler.php file. If you wish a copy post here and I will get you one.

Alex Chartier commented on Jan 12, 2019

Ran into a slight issue. Before I go into that would it be possible to roll these changes into mainline code? Nothing I changed should affect any other operations and for those customers who are on public servers PhantomJsCloud may be a good alternative for them.

To the issue at hand. Due to PhantomJsCloud being offsite from the main server we need to ensure all url's are fully qualified, i.e. include the http::/sitename/. This has been fixed for most of the included css and script files as noted in the above posting, except those that are pulled in dynamically by the widget init function. I would like to see a settings option, for example siteURL, will will be appended to the resources that are created by the getResources function in src/core/Widget.php. This function calls convertHierachicalResources to produce the url so if we can set siteURL in the settings and have this convertHierachicalResources function pre-pend the url it creates with this site value then all would be good.

This is effectively what I need, but, you may have a better way to actually implement it.

I await your feedback.

Alex Chartier commented on Jan 13, 2019

On further testing the above does not work. I have found it easiest to simply insert script tags in my view for the scripts required.

I would still like to have the phantomJsCloud enhancements ported to production if possible. I can provide whatever assistance is required.

KoolReport commented on Jan 14, 2019

By setting the assets url in settings() function, you can make absolute url for all koolreport assets, for example:

"assets"=>array(
    "path"=>"../../assets"
    "url"=>"https://domain.com/assets"
)
Alex Chartier commented on Jan 15, 2019

Yes, that works well, thanks.

the issue I am having now is that I am not getting the table row shading in pdf output that I am getting on the screen. Is there some extra CSS I need for this?

I have attached a screen grab of the screen display and the resulting pdf.


![](https://cdn.koolreport.com/assets/images/editor/c4/image5c3df4dab159f.png)

Alex Chartier commented on Jan 15, 2019

Here is the pdf

ingmar roos commented on Jan 16, 2019

Nice solution Alex,

Could you please explain the changes that you made in Handler.php as well and/or post modified Handler.php file for other users.

Alex Chartier commented on Jan 16, 2019

Hello Ingmar,

The changes I made are not changes you want your average user to make, particularly one change which requires running composer to add another library to the koolreport library. However, if you like I can document the changes required and send them through to you via the support email system if you are willing to integrate into the production code.

ingmar roos commented on Jan 18, 2019

Thank you Alex for willingness to help. As I am not expert level user myself then I do not think that I will be able to go through this all and hence will wait for the KooReport team to implement their own cloudservice with documentations on how to get it going.

KoolReport commented on Jan 25, 2019

We have created CloudExport package and a new cloud service, hope to receive your feedback. More details, please go to this thread CloudExport package beta version.

The CloudExport will able to access other online services like PhantomJsCloud in future.

Thanks!

Alex Chartier commented on Jan 25, 2019

I am travelling for the next 2 months so will be unable to do any testing on this. Question though, are the pdf options the same as they are for phantomjs?

KoolReport commented on Jan 25, 2019

More or less are the same.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
suggestion

None