MozillaZine

html conversion to pdf with Mozzilla is possible?

Discuss building things with or for the Mozilla Platform.
TO_Webmaster
 
Posts: 3
Joined: June 12th, 2008, 4:27 am

Post Posted June 12th, 2008, 4:37 am

Did you get this working with PHP?

It works really fine on the command line using Xvfb and setting the DISPLAY-variable, but when I try to use this in PHP, nothing happens.

Code: Select all
...
system("Xvfb :42 > /dev/null &");
echo shell_exec('env DISPLAY=":42" /mypath/firefox -Profile "/myprofilepath" -print http://someurl.html -printmode pdf -printfile /somefile.pdf');
...


The same commands work fine on the command line.
Xvfb works fine in PHP, I used it in other PHP-scripts before. This should not be the problem.

TO_Webmaster
Last edited by TO_Webmaster on April 13th, 2009, 4:48 pm, edited 1 time in total.

luca.colli
 
Posts: 14
Joined: June 2nd, 2008, 8:03 am

Post Posted June 12th, 2008, 8:58 am

... mmm we have the same problem...
evrything goes ok if you run firefox in manual mode...

But i have the same problem run firefox from PHP...
seems a 'user' problem... firefox is alweys lunch like a Net Service...

For run an application in PHP in the remote server you need to run firefox like a Php autorized user...
but we're not schure.... we haven't find a way yeat

please if you have some idea post here...
Bye"
--
Luca Colli

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted June 15th, 2008, 9:42 am

How about .bat file or shell script or something like that? I mean, php -> bat -> firefox.

TO_Webmaster
 
Posts: 3
Joined: June 12th, 2008, 4:27 am

Post Posted June 15th, 2008, 9:49 am

It works fine using Portable Firefox 3.0 with wine 1.0. (Here we see that Windows is better than Linux :lol: .)

First, I configured Portable Firefox under Windows (command line print plugin, print options, ...)

Then...

After compiling Wine 1.0 (as a user, not as root), I created some_folder containing a .wine folder belonging to the webserver-user (it does not work, if .wine does not belong to the webserver-user!). In this .wine-folder there is my wine-configuration. In some_folder, there is also an .Xauthority containing just the word localhost.

Then you can use the following commands:

Code: Select all
exec("killall Xvfb");
exec("rm -f /tmp/.X42-lock");
exec("Xvfb -auth some_folder/.Xauthority :42 > /dev/null &");

exec('env DISPLAY=:42 HOME=some_folder /your/wine/path/wine z:/path_to_your_firefox/FirefoxPortable.exe -print http://some.site/something_to_print.html -printmode pdf -printfile "z:\\your\\path\\with\\double-backslashes\\your_file.pdf"');

exec("killall Xvfb");


If you find any bugs or have any ideas, please let me know.

TO_Webmaster

luca.colli
 
Posts: 14
Joined: June 2nd, 2008, 8:03 am

Post Posted June 24th, 2008, 11:29 pm

Torisugari do you ave resolved command line bug ?
--
Luca Colli

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted July 9th, 2008, 8:19 pm

luca.colli wrote:Torisugari do you ave resolved command line bug ?

I'm sorry for being late. Probably the problem is gone now. Could you test it, if you don't mind?

http://torisugari.googlepages.com/commandlineprint2

luca.colli
 
Posts: 14
Joined: June 2nd, 2008, 8:03 am

Post Posted July 14th, 2008, 1:42 am

Hi Torisugari

I find a bug in the PDF save.
If you write :

firefox.exe -print http://www.kgo.it/concss.html -printmode pdf -printfile C:\Test_Name.pdf

The file is completely white...
but if you use -printmode printer evrythin is ok....

bye
--
Luca Colli

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted July 14th, 2008, 5:06 am

luca.colli wrote:If you write :

firefox.exe -print http://www.kgo.it/concss.html -printmode pdf -printfile C:\Test_Name.pdf

The file is completely white...

I copied&pasted that line and it works for me.
http://torisugari.googlepages.com/Test_Name.pdf
Isn't it the result you expected?

If you find more info to reproduce the problem, please let me know that.

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted July 14th, 2008, 5:16 am

Torisugari wrote:If you find more info to reproduce the problem, please let me know that.

Don't mind it. I found that. Well, a lot of APIs which worked Fx2 stopped working now...

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted July 14th, 2008, 7:13 am

Probably fixed in ver. 0.4.3. Thanks for the report.

boltrook
 
Posts: 3
Joined: July 22nd, 2008, 7:21 am

Post Posted July 22nd, 2008, 7:32 am

I'm attempting to implement this with perl on a linux server. Your description seems to identify that this can be used on all platforms. The "firefox -print http://www.google.com -printmode pdf -printfile /tmp/test.pdf" will return to me "Error: no display specified" in all my tests. On my windows laptop I can execute the command with the path on my disk and it will perform the operation very well. This would be an excellent solution for what we're trying to do converting html letters into pdfs. Please let me know if there is something else we can try to use this great extension.

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted July 22nd, 2008, 8:46 am

Let me guess, your linux server is headless (and/or you don't have X running).

Phil

boltrook
 
Posts: 3
Joined: July 22nd, 2008, 7:21 am

Post Posted July 22nd, 2008, 9:32 am

an x server is running but there is no display attached to the system. Is there a display setting or substitute we can use? We got the display routed to one of our computers to try the command there (on someone's macbook) but the extension didn't respond. There was no message or result.

Philip Chee

User avatar
 
Posts: 6475
Joined: March 1st, 2005, 3:03 pm

Post Posted July 22nd, 2008, 10:41 am

You could try using a virtual frame buffer (google for Xvfb) http://en.wikipedia.org/wiki/Framebuffer#Virtual_framebuffers and point Firefox to use that display.

Phil

Torisugari
 
Posts: 1634
Joined: November 4th, 2002, 8:34 pm
Location: Kyoto, Nippon (GMT +9)

Post Posted July 23rd, 2008, 6:23 am

boltrook wrote:I'm attempting to implement this with perl on a linux server. Your description seems to identify that this can be used on all platforms. The "firefox -print http://www.google.com -printmode pdf -printfile /tmp/test.pdf" will return to me "Error: no display specified" in all my tests.

Before trying the extension, you can confirm whether Firefox runs fine first. As Philip Chee already pointed out, the best solution would be to use virtual display, like Xvfb. See also another post in this thread.

TO_Webmaster wrote:Did you get this working with PHP?



Ist works really fine on the command line using Xvfb and setting the DISPLAY-variable, but when I try to use this in PHP, nothing happens.



Code: Select all
...
system("Xvfb :42 > /dev/null &");
echo shell_exec('env DISPLAY=":42" /mypath/firefox -Profile "/myprofilepath" -print http://someurl.html -printmode pdf -printfile /somefile.pdf');
...




The same commands work fine on the command line.

Xvfb works fine in PHP, I used it in other PHP-scripts before. This should not be the problem.



TO_Webmaster

nsAppRunner.cpp wrote:
Code: Select all
      // display_name is owned by gdk.
      const char *display_name = gdk_get_display_arg_name();
      if (!display_name) {
        display_name = PR_GetEnv("DISPLAY");
        if (!display_name) {
          PR_fprintf(PR_STDERR, "Error: no display specified\n");
          return 1;
        }
      }
      display = gdk_display_open(display_name);
      if (!display) {
        PR_fprintf(PR_STDERR, "Error: cannot open display: %s\n", display_name);
        return 1;
      }

gdk.c wrote:
Code: Select all
G_CONST_RETURN gchar *
gdk_get_display_arg_name (void)
{
  if (!_gdk_display_arg_name)
    {
      if (_gdk_screen_number >= 0)
   _gdk_display_arg_name = _gdk_windowing_substitute_screen_number (_gdk_display_name, _gdk_screen_number);
      else
   _gdk_display_arg_name = g_strdup (_gdk_display_name);
   }

   return _gdk_display_arg_name;
}

The direct reason why XULRunner complains "no display specified" is that the machine lacks both a valid result of gdk-get-display-arg-name and DISPLAY enviroment variable. As TO_Webmaster described, setting DISPLAY is also important, when your machine has no real display.

Return to Mozilla Development


Who is online

Users browsing this forum: No registered users and 1 guest