• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

printing without any dialog window?

Explorer ,
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

Hello peeps!

I'm doing a kiosk-type flash application. and i have a print function at the end of the application, to print the receipt... but..

1) whenever I press the PRINT button in flash, it will pop out a printing preference window and I will have to press OK then it will print. In other words, is it possible to skip selection printer window? I must print "directly" the job in the default printer. I'm develping a kiosk application and need print a "receipt".

2) and then is there any code to check if the printing succeed or fail? so that if it fail, i will display a fail msg in flash.. etc..

TOPICS
ActionScript

Views

11.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 23, 2011 May 23, 2011

Hi,

@Zainuu

below is minimal code required to print without dialog (it works on my machine) - but without advanced settings, see below link description:

var pj:PrintJob = new PrintJob();

var started:Boolean = pj.start2(null, false);

if(started)

{

     pj.addPage(this);

     pj.send();

};

pj = null;

you're calling start(...) and start2(...) in your code, so you would get dialog visible.

Here is some documentation from Adobe on how ot configure printing options for use with start2(...), good reading:

ht

...

Votes

Translate

Translate
Enthusiast ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Hi,

from AIR 2.0 (or newer) there is option to configure print job settings without user interaction, select printer and then start print job without system dialog:

http://forums.adobe.com/thread/562953?decorator=print&displayFullThread=true

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/printing/PrintJob.html#start2()

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/printing/package-detail.html

So you need to developer with AIR SDK and then content needs to be deployed with AIR runtime,

regards,

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Hi, I'm currently using Flash Projector for my application. How do I change it into AIR?

so I just use these 2 lines of code to bypass it?

import flash.printing.PrintUIOptions;

myPrintJob.start2(null, false);

Thank you and looking forward for your reply soon...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Hello,

that's not as easy as just importing correct api from flash.printing.* package.

Your authoring tool needs to support AIR SDK in order to use runtime configuration that for example suports PrintJob.print2(....) method or allows  to set "printer" property via code. Flash CS5 or FLash Builder allows IDE-based authoring of Flash content that would run with AIR runtime, see quick start quides:

http://www.adobe.com/devnet/air/quick_start_as.html

If you export only executable (projector) from your authoring tool it will use Flash runtime - where advanced additions of AIR SDK are not available (the good news is that AIR SDK simply adds features to your existing Flash actionscript code, so there is easy way to move entire existing project into AIR SDK if required I think),

regards,

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

sorry but what do you mean by my authoring tool needs to support AIR SDK in order to use runtime configuration ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Hi,

Flash CS5 or later (I'm not sure which version of Flash CS* started to support full AIR sdk devleopment), Flex Builder or Flash Builder (all Adobe's authoring tools) or any 3rd party authoring tool that could author and deploy AIR SDK based content (e.g. FlashDevelop - but that could be cumbersome to correctly setup such 3rd party authoring tools/IDEs to fully work with AIR SDK tools)

regards,

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

hello! yes I'm using CS4 to create the application. So if I convert to AIR and use that 2 lines of codes, that would be all? Or I need a 3rd party program?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2011 May 19, 2011

Copy link to clipboard

Copied

Apparently you can create AIR2 from Flash CS4.

Here's CS4 doc for publishing to AIR:

http://help.adobe.com/en_US/Flash/10.0_UsingFlash/WSF0126B20-BFF4-4c50-9978-BCA47C8C3C3F.html

You need AIR2 SDK. Here's info - scroll down to "Flash Professional CS4" how-to section:

http://www.adobe.com/support/documentation/en/air/2/releasenotes_developers.html

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 22, 2011 May 22, 2011

Copy link to clipboard

Copied

Hi, thanks for the reply above. I have checked my AIR version using this http://kb2.adobe.com/cps/407/kb407625.html and it shows 2.04.13090 under the Detail tab of Adobe AIR.dll. So I asume that my AIR is version 2.0?

So after knowing that it is version 2.0 I quickly went to use the sample code from the tutorial link below and tried to add in the 2 lines of codes:

import flash.printing.PrintUIOptions;

printJob.start2(null, false);

http://www.riacodes.com/flash/how-to-print-with-as3/

The above link is a sample code that I took and convert it into AIR. But I keep getting these errors while trying to add in those 2 lines of codes..

import flash.printing.PrintUIOptions;

print_btn.addEventListener(MouseEvent.CLICK,printContent);

function printContent(evt:MouseEvent) {
     var printJob:PrintJob = new PrintJob();
     
     if (printJob.start()) {
          
          if (content_mc.width>printJob.pageWidth) {
               content_mc.width=printJob.pageWidth;
               content_mc.scaleY=content_mc.scaleX;
          }
          
          printJob.addPage(content_mc);
          printJob.start2(null, false);
          printJob.send();
     }
}

1172: Definition flash.printing:PrintUIOptions could not be found.

1061: Call to a possibly undefined method start2 through a reference with static type flash.printing:PrintJob.

This is a link to download my source code that I edited from the above sample tutorial link: http://www.mediafire.com/?xbdiopgb8vn8yh4

Please help..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Your AIR runtime version is nothing to do with your AIR compiler version. Have you installed the SDK?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Hi, thanks for your reply. I'm not sure about the SDK. What is it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Hi,

@Zainuu

You need AIR2 SDK. Here's info - scroll down to "Flash Professional CS4" how-to section:

http://www.adobe.com/support/documentation/en/air/2/releasenotes_developers.html#h

This doc outlines what needs to be done manually to update tool chain (SDK, air compiler, etc) to author updated content with CS4.

You need to download updated AIR SDK, e.g.:

http://www.adobe.com/products/air/sdk/

and overlay it with your CS4 installation > as per documentation.

regards,

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Hello peter, it's nice to see to here! So whenever I create a AIR 2.0 project, I have to follow this steps below?

http://www.adobe.com/support/documentation/en/air/2/releasenotes_developers.html#h

How to locate the application descriptor file for a new project.

For a new project, you will need to do the following steps to create and update the application descriptor file:

  1. Launch Flash Professional CS4.
  2. Select "File > New...".
  3. Select "Flash File (Adobe AIR)" and click "OK".
  4. Select "Flash > Save" and click "OK".
  5. Select "File > AIR Settings..." and click "OK" with the default settings. This will create the application descriptor file.
  6. Navigate to the folder containing your .swf file and locate the .xml file. If the .swf file is named mygame.swf, the application's descriptor file will be "mygame-app.xml".
  7. Open the application descriptor .xml file in a text editor.
  8. Replace the namespace with "http://ns.adobe.com/air/application/2.0" and save the file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Hi, I have sucessfully compiled and can CRTL+ENTER start the application but the printing window still pops out when I press print button. Here is my code, can anyone tell me which code need to remove/add?

I have already read http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/printing/PrintJob.html... but I dont seem to know how to use them.

import flash.printing.PrintUIOptions; print_btn.addEventListener(MouseEvent.CLICK,printContent); function printContent(evt:MouseEvent) {      var printJob:PrintJob = new PrintJob();           if (printJob.start()) {                     if (content_mc.width>printJob.pageWidth) {                content_mc.width=printJob.pageWidth;                content_mc.scaleY=content_mc.scaleX;           }                     printJob.addPage(content_mc);           printJob.start2(null, false);           printJob.send();      } }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

Hi,

@Zainuu

below is minimal code required to print without dialog (it works on my machine) - but without advanced settings, see below link description:

var pj:PrintJob = new PrintJob();

var started:Boolean = pj.start2(null, false);

if(started)

{

     pj.addPage(this);

     pj.send();

};

pj = null;

you're calling start(...) and start2(...) in your code, so you would get dialog visible.

Here is some documentation from Adobe on how ot configure printing options for use with start2(...), good reading:

http://help.adobe.com/en_US/as3/dev/WS059b243ca571213c1e18d17a124d9fca6d8-8000.html

regards,

Peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 23, 2011 May 23, 2011

Copy link to clipboard

Copied

LATEST

Hi Peter,

Thanks it works greatly. Currently I'm trying to set the printer settings.  The followings are the settings I'm trying to set. Is that all the settings I can set?

pj.copies = 2;

pj.firstPage = 1;

pj.lastPage = 3;

pj.orientation = PrintJobOrientation.LANDSCAPE;

pj.minPage = 1;

pj.maxPage = 2;

pj.selectPaperSize(PaperSize.ENV_10);

I noticed that firstPage,lastPage,minPage and maxPage cannot be used..

Full Code:

var pj:PrintJob = new PrintJob();

pj.copies = 2;

pj.firstPage = 1;

pj.lastPage = 3;

pj.orientation = PrintJobOrientation.LANDSCAPE;

pj.minPage = 1;

pj.maxPage = 2;

pj.selectPaperSize(PaperSize.ENV_10);

var started:Boolean = pj.start2(null, false);

if(started)

{

     if (content_mc.width>pj.pageWidth) {

               content_mc.width=pj.pageWidth;

               content_mc.scaleY=content_mc.scaleX;

          }

     pj.addPage(content_mc);

     pj.send();

};

pj = null;

The followings are my steps to compile and run as AIR 2.0 SDK. I hope I did it correctly.

How to change from Flash Projector to AIR?

Step 1: In your Adobe Flash CS4 project, click File->Publish Settings (CTRL+SHIFT+F12)->click Flash tab->under Player choose Adobe AIR 1.5->click Settings and click OK all the way till window close.

Step 2: A .xml will be created in the same folder with your .fla .swf etc... Open the .xml with notepad.

Step 3: Replace http://ns.adobe.com/air/application/1.5 with http://ns.adobe.com/air/application/2.0


*Before you start Step 1, ensure that your system has AIR 2.0 SDK installed and configured.

AIR 2.0 SDK: http://www.adobe.com/products/air/sdk/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines