PDA

View Full Version : printing support


madtux666
04-07-2008, 04:00 AM
Hi,


I try to implement printing functionality in my Laszlo app.

I have checked below wiki page:
http://wiki.openlaszlo.org/Printing

and forum posts as well:
http://forum.openlaszlo.org/showthread.php?t=7500&highlight=print
http://forum.openlaszlo.org/showthread.php?t=373&highlight=print
http://forum.openlaszlo.org/showthread.php?t=7827&highlight=print


My code is:

<!-- PRINTING -->
<canvas width="600" height="800" debug="true">

<view name="test1" >

<simplelayout axis="y" spacing="10"/>
<view name="maj" bgcolor="red" width="200" height="60"/>
<view bgcolor="yellow" width="200" height="60"/>
<view bgcolor="blue" width="200" height="60"/>

<button name="invokePrinter">invokePrinter()

<handler name="onclick">
<![CDATA[
this.parent.print(this.parent.maj);
]]>
</handler>

</button>

<method name='print' args='inView'>
<![CDATA[

Debug.write('inView: ', inView);

var lPrintJob;
var lPageAdded = false;
var lOriginX;
var lOriginY;
var lMovieRef;
var lNumRows;
var lNumCols;
var lRow;
var lCol;
var lPagesPrinted = 0;

lMovieRef = inView.getMCRef();

Debug.write('lMovieRef: ', lMovieRef);

lPrintJob = new PrintJob();

Debug.write('lPrintJob: ', lPrintJob);

if (lPrintJob.start())
{
// figure out how many pages wide and high
lNumCols = Math.ceil(inView.width/lPrintJob.pageWidth);
lNumRows = Math.ceil(inView.height/lPrintJob.pageHeight);

Debug.write('lNumCols: ', lNumCols);
Debug.write('lNumRows: ', lNumRows);

for (lRow=0; lRow<lNumRows; lRow++)
{
for (lCol=0; lCol<lNumCols; lCol++)
{
lOriginX = lCol*lPrintJob.pageWidth;
lOriginY = lRow*lPrintJob.pageHeight;
lPageAdded = lPrintJob.addPage(lMovieRef, {xMin:lOriginX,
xMax:lOriginX + lPrintJob.pageWidth,
yMin:lOriginY,
yMax:lOriginY + lPrintJob.pageHeight},
{printAsBitmap:true});

Debug.write('lPrintJob.pageWidth: ', lPrintJob.pageWidth);
Debug.write('lPrintJob.pageHeight: ', lPrintJob.pageHeight);
Debug.write('lOriginX: ', lOriginX);
Debug.write('lOriginY: ', lOriginY);
Debug.write('lPageAdded: ', lPageAdded);
Debug.write('lMovieRef: ', lMovieRef);

if ( !lPageAdded )
break;

lPagesPrinted++;

Debug.write('lPageAdded (at the end of for loop): ', lPageAdded);
}

if ( ! lPageAdded )
break;
}

if (lPagesPrinted > 0)
lPrintJob.send();
}

// clean up
delete lPrintJob;

]]>
</method>

</view>

</canvas>



Basiclly it looks that new pages aren't added to printjob object. Printing dialog also looks strange (please check attachment).


Has somebody had working print method for Laszlo 4.0.11?



Regards,
Madtux

rcyeager
04-07-2008, 05:21 PM
It works if you change your onclick handler to:

this.parent.print(canvas.test1);

The downside is that all three colored boxes print, along with the button.

The routine you are using is the same as I use for printing. Not exactly sure what the issue is that prevents just the red view from printing.

I *think* that only canvas-level views can be printed, not subviews. In my printing routines, I create views far outside the visible canvas region (coordinates 10,000 x 10,000) for formatting the view prior to sending it to the print routine. Maybe I did this as a workaround, so that I could format views for printing on the canvas-level view. Has been a year since I last worked on print code, so I can't exactly remember why I did it like that, except to say that I know it works.

Robert
http://www.qrowd.com
http://www.cooqy.com

spoco2
04-07-2008, 07:18 PM
It all works fine for me in 3.4.x if I change the onclick to


<handler name="onclick">
<![CDATA[
this.parent.print(this.parent);
]]>
</handler>

madtux666
04-09-2008, 03:05 AM
Hi,


First of all I would like to thank you for replies.

@rcyeager, I have followed your advice, however still I can not print anything. Below I have attached content of debug window:


inView: «lz.view#0| #test1»
lMovieRef: «MovieClip#1| _level0.spriteroot.$m0 [200.00 x 236.00]*[1.00 0.00 0.00, 0.00 1.00 0.00, 0 0 1]»
lPrintJob: «object#2| {orientation: 0, pageWidth: 0, pageHeight: 0, paperWidth: 0, paperHeight: 0}»
lNumCols: 1
lNumRows: 1
WARNING @printing.lzx#68: reference to undefined property 'pageWidth'
lPrintJob.pageWidth: undefined
WARNING @printing.lzx#69: reference to undefined property 'pageHeight'
lPrintJob.pageHeight: undefined
lOriginX: 0
lOriginY: 0
lPageAdded: false
lMovieRef: «MovieClip#1| _level0.spriteroot.$m0 [200.00 x 236.00]*[1.00 0.00 0.00, 0.00 1.00 0.00, 0 0 1]»



@spoco2, I have checked your code also, but I have got the same error as earlier.


It is weird, do you use any additional includes or libraries?


Regards,
Madtux

rcyeager
04-09-2008, 09:15 AM
Hi,

I am using the code you provided as-is, using the one line change I indicated in the onclick handler above.

So, the only other differences can be OpenLaszlo, Flash, operating system, or the browser.

I am using a nightly 4.0.x build from December, latest Flash 9, WinXP SP3, Firefox 2.0.0.13.

Here is the output from the debugger I receive:


inView: «lz.view#0| #test1»
lMovieRef: «MovieClip#1| _level0.spriteroot.$m0»
lPrintJob: «object#2| {orientation: 0, pageWidth: 0, pageHeight: 0, paperWidth: 0, paperHeight: 0}»
lNumCols: 1
lNumRows: 1
lPrintJob.pageWidth: 576
lPrintJob.pageHeight: 763
lOriginX: 0
lOriginY: 0
lPageAdded: true
lMovieRef: «MovieClip#1| _level0.spriteroot.$m0»
lPageAdded (at the end of for loop): true


Robert
http://www.qrowd.com
http://www.cooqy.com

spoco2
04-09-2008, 01:51 PM
Also, what are you printing to? The properties of the printjob are created after you chose a printer (along with page size and orientation) and seeing as it's the printing class that's throwing the error, it would seem it's pretty low level such as that. Are you printing to a real printer or an acrobat distiller, or something else?

madtux666
04-10-2008, 12:20 AM
Hi lads,

I have tried to print on local network printer.

I am working on Linux Printing regular documents work fine, however I can not print that Laszlo page. Fortunately method works fine on MS systems.


Thanks you for your help ;)

madtux666
04-17-2008, 02:13 AM
Hi lads,

I still have one question. is there any chance that Laszlo will be able to control size of printout? I try to print quite complex, custom component (base class is LzView). I can not control size from printing dialog ( I have tested scaling, changing paper size, landscape orientation, etc...) always result is bigged than paper (scaling even doesn't work).

I have seen somewhere here post about printing (I cannot find it now) and I remember that view size was strictly set to fixed width/height to fit paper size. In my situation I can not do it (to keep uncrowded and useable). Also I would like to avid creating second smaller, synchronized component just for printing purposes.


So, have somebody faced such a problem and have solution?



Regards,
Madtux

rcyeager
04-17-2008, 07:49 AM
What you are dealing with is the functionality provided by Flash, so you need to search the Flash documentation and forums to find help.

Here is some Flash documentation that talks about print scaling:

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000334.html

Robert
http://www.qrowd.com
http://www.cooqy.com

spoco2
04-17-2008, 02:31 PM
I think that madtux has the same issue I have, in that while the flash docs say to scale the area you're going to print (using the xscale and yscale attributes), these are not attributes visible through to Laszlo, and when I've tried playing with them it's done pretty much nothing.

It would be great for Laszlo to have a built in method for scaling to fit the print area as it would be ENORMOUSLY helpful. As madtux said, creating a view of the print area size and then building a printview into it that's the right dimensions is almost impossible for our app too... it really is a scale to fit that's required.

Laszlo team?

rcyeager
04-17-2008, 04:27 PM
I wouldn't expect the Laszlo team to implement this unless it could be done in a way that supports multiple runtimes, as Laszlo is not a Flash-specific technology.

There are many examples of Flash functionality that are not surfaced in Laszlo for this reason.

Robert
http://www.qrowd.com
http://www.cooqy.com

spoco2
04-17-2008, 07:38 PM
However it is a fairly basic requirement for a lot of apps, and it's not like you can't print from html pages.

There are calls and features which Laszlo does currently support that are unavailable within dhtml (can't think off hand of any, but I have come across them), so they aren't completely adverse to the notion.

madtux666
04-18-2008, 12:15 AM
Hi,

Thanks for replies. I will mess around for a while next week. I will post if I find any solution (as I understood it could be challenging task).



Regards,
Madtux

madtux666
05-01-2008, 02:28 AM
Hi Lads,

I has investigated issue for a while, and unfortunately it looks like there is no smart solution. I will try to create separate object, just for printing purposes (or maybe even secondary small app invoked from main app?).



Regards,
Madtux

MBachstein
04-24-2009, 02:07 AM
Hello,

I want to print a view out of my OpenLaszlo application. When I print this view it is printed on 2 pages.

Does anybody know how I can scale it down so that it's printed on 1 page?

Kind Regards,
Marc


<canvas width="1600" height="1800" debug="true">

<view name="mainView" >
<simplelayout axis="y" spacing="10"/>

<!-- picture -->
<view name="picture" source="http://www.eviaggiatori.it/sfondi/1024x768%20golden%20gate.jpg"/>

<button name="invokePrinter">invokePrinter()
<handler name="onclick">
this.parent.print(this.parent);
</handler>
</button>

<!-- printing method -->
<method name='print' args='inView'>
<![CDATA[

Debug.write('inView: ', inView);

var lPrintJob;
var lPageAdded = false;
var lOriginX;
var lOriginY;
var lMovieRef;
var lNumRows;
var lNumCols;
var lRow;
var lCol;
var lPagesPrinted = 0;

lMovieRef = inView.getMCRef();

Debug.write('lMovieRef: ', lMovieRef);

lPrintJob = new PrintJob();

Debug.write('lPrintJob: ', lPrintJob);

if (lPrintJob.start())
{
// figure out how many pages wide and high
lNumCols = Math.ceil(inView.width/lPrintJob.pageWidth);
lNumRows = Math.ceil(inView.height/lPrintJob.pageHeight);

Debug.write('lNumCols: ', lNumCols);
Debug.write('lNumRows: ', lNumRows);

for (lRow=0; lRow<lNumRows; lRow++)
{
for (lCol=0; lCol<lNumCols; lCol++)
{
lOriginX = lCol*lPrintJob.pageWidth;
lOriginY = lRow*lPrintJob.pageHeight;
lPageAdded = lPrintJob.addPage(lMovieRef, {xMin:lOriginX,
xMax:lOriginX + lPrintJob.pageWidth,
yMin:lOriginY,
yMax:lOriginY + lPrintJob.pageHeight},
{printAsBitmap:true});

Debug.write('lPrintJob.pageWidth: ', lPrintJob.pageWidth);
Debug.write('lPrintJob.pageHeight: ', lPrintJob.pageHeight);
Debug.write('lOriginX: ', lOriginX);
Debug.write('lOriginY: ', lOriginY);
Debug.write('lPageAdded: ', lPageAdded);
Debug.write('lMovieRef: ', lMovieRef);

if ( !lPageAdded )
break;

lPagesPrinted++;

Debug.write('lPageAdded (at the end of for loop): ', lPageAdded);
}

if ( ! lPageAdded )
break;
}

if (lPagesPrinted > 0)
lPrintJob.send();
}

// clean up
delete lPrintJob;

]]>
</method>
</view>
</canvas>

madtux666
04-27-2009, 02:53 AM
Hi MBachstein,

I have described pretty ugly solution in my last post:
I have created object that was a copy of main one but smaller (ex. 6px fonts instead of 10, smaller gfx icons, etc.). Everything was approximately 50% size of original, so printout fits A4 paper sheet.

I am also interested if there is better solution!


Regards,
Madtux