Current position:  Home > Default > Printing with PrintJob

Printing with PrintJob

Time:November 30
Advertisement
Hi there!
I have got a search dialog and I want to print the search criterias (labels) on a cover page and the search result (datagrid) following the cover page.
Up to now, I used the FlexPrintJob class. Everything works well.
Now I have to move to PrintJob because I need to force the pages containing the search result to be printed out in landscape, even if the user has selected to print out portrait within the operating-system-related print dialog.
Further restriction: I can't embed fonts.
But let's start with a simple question:
How can I get this working? The page remains blank when I try this.
var pj:PrintJob = new PrintJob();
if (pj.start())
     var testLabel:Label = new Label();
     testLabel.width = 400;
     testLabel.text = "TEST";
     var container:UIComponent = new UIComponent();
     container.addChild(testLabel);
     pj.addPage(container);
     pj.send();
Thanks, Cheers!
Advertisement
My next step, which was the original problem I tried to solve, is the rotation to landscape of the content. Since I can't make use of embedded fonts I see only the solution to create an image of the page and rotate it 90 degrees. The following code works in that way that it makes the rotation, but the content disappears and instead is shown a grey bar. Without rotation the page is shown as attached.
var pj:PrintJob = new PrintJob();
if (pj.start())
var container:VBox;
var vBox:VBox;
try {
      var testLabel:Label = new Label();
      testLabel.width = 400;
      testLabel.text = "TEST";
      container = new VBox();
      container.width = pj.pageWidth;
      container.height = pj.pageHeight;
      container.setStyle("backgroundColor", "#FFFFFF");
      container.addChild(testLabel);
      addChild(container);
      container.validateNow();
      var bitmap:BitmapData =
          ImageSnapshot.captureBitmapData(testLabel);
      var img:Image = new Image();
      // comment out following line for no rotation
      img.rotation = 90;
      img.width = 400;
      img.height = 20;
      img.source = new BitmapAsset(bitmap);  
      vBox = new VBox();  
      vBox.addChild(img);
      vBox.width = pj.pageWidth;
      vBox.height = pj.pageHeight;
      addChild(vBox);
      vBox.validateNow();
      pj.addPage(vBox);
      pj.send();
catch (error:Error)
  Alert.show(error.toString());
finally {
   // clean-up code
   removeChild(container);
   removeChild(vBox);
Do I have to call something when I rotate the component?

Printing problems (printjob, 1.2.2, 1.3, WinNT and HP printers)

2015-10-11

We are experiencing a landry list of problems with java 1.2.2 and 1.3 when trying to print reasonably simple reports. I am just curious if anyone has encounterd problems like these, or if anyone has had any luck working around them. We would really l

Printing with printjob/ toolkit method...

-0001-11-30

after a week of trying to implement the PrinterJob method of printing and not getting anywhere, i am now using the PrintJob/ toolkit method. i am printing a JPanel which holds 6 other JPanels and 1 JLabel with a .gif image on it. all 6 of the contain

Suppress the Print dialog box in Air /Flex

2015-10-11

Hello, I am trying to print the pdf files(which is located in my system) directly in the printer without showing print dialog box . I tried to print the screen without displaying print dialog box using flash.printJob.start2(). but am not able to prin

Print dialog not displaying when trying to print PDF document

2015-10-11

Hello All, I am using below code to print a pdf file. And the same code working fine when i am using with simple java class. and if i am using the same code with my jsf backing bean action method it was not working. Code here: Document document = new

How to print text/data in flex 3 using printer???Plz help...

2015-10-11

   Hi,           plz tell me the way to print text/data using printer in flex.  I tried the FlexPrintJob class. but it takes object of a container to be printed & prints the visible content of that container(along with scrollbars), bt i want to print

Print HTML File Without Showing on Screen

2015-10-11

Hi Everyone Is there a way to print a file (in particular, an html file) from a java app without actually displaying the file on the screen. ie. print from command line. I am creating an html file from within java app and would like to print it in on

How to print the whole JFrame

2015-10-11

Hi, I got this code somewhere from the net. import java.awt.*; import javax.swing.*; import java.awt.print.*; /** A simple utility class that lets you very simply print *  an arbitrary component. Just pass the component to the *  PrintUtilities.print

How can I Print a JPanel including all added Components?

2015-10-11

Hello dear saviours, I have a JPanel object which is responsible for displaying a Graph. I need to Print the Components of this JPanel as close to what they look like to the user as possible. I thought about casting the JPanel into an Image of some k

URGENT ! Help to printing contents of a panel (Plz Help me)

2015-10-11

hi guys, i developed a application which consists of lot of information on a panel, i am using print utilities and printing the panel but its printing only the visible part of the panel and its printing a single page. is there any way i can print the

Printing problem with muliple page 2D graphics.........URGENT

2015-10-11

/*hi I want to print the drawings that i create in my painting application. Following is the extract from my drawing application, which takes care of the printing part. The problem i am facing is that, i am able to print only one page, the other part

Printing to a PDF

2015-10-11

I have the following class: import java.awt.*; import javax.swing.*; import java.awt.print.*; public class PrintUtilities implements Printable {   private Component componentToBePrinted;   public static void printComponent(Component c) {     new Prin

Sending a JPanel to the printer...

2015-10-11

All, I wasn't sure if this was the appropriate forum for this, but I couldn't find one specific to printint to a printer. I'm trying to send a JPanel to a printer. I have the following routine which seems to more or less work, but exhibits a few prob

Problems with printing the text in JTextPane

2015-10-11

Hello I need to print the text in a text pane. It prints the first page of the text pane and it doesn't print the rest of the text. I don't know what the problem is. The code I am using, is below. I Thank you. LilyLay import java.awt.*; import javax.

Printing the text in JTextPane

2015-10-11

Hello I need to print the text in a text pane. It prints the first page of the text pane and it doesn't print the rest of the text. I don't know what the problem is. The code I am using, is below. I Thank you. LilyLay import java.awt.*; import javax.

Printing in Mac OS X

2015-10-11

Hello all, I created a printable class that works in Windows and Linux, but for some reason will not work on Mac OS X. It either prints a blank page or throws a nasty exception: Exception in thread "Thread-0" java.lang.NullPointerException at ja

Need Printing Help (location to top-left?)

2015-10-11

im able to print out a JFrame, no problem..but the onscreen image and whats printed on paper arent exactly the same 1) Printed is 1.5 - 2X bigger than onscreen (1280x1024 resolution) 2) Printed starts near the middle of the page, not at the top left

Printjob System Parameter...

-0001-11-30

Hi all, I am calling a report from a form using run_product. I want to print it directly but want the printer dialog box should appear before printing. Tht can be done assigning parameter 'DESTYPE'='PRINTER' and 'PRINTJOB'='YES' but this is not worki

CR XI R2 Viewer not obeying printer collation setting?

-0001-11-30

Just noticed this. Steps to duplicate: Print a printjob to the viewer. Hit print button in Viewer. Change to 2 copies, change collation, print. Result is the same whether you select a collation of 111 222 333 or 123 123 123. Printout is printed as 11

Print job becomes massive with Flash Player 10.1 & 10.2?

-0001-11-30

First off, some info.  This is rather old code, written in 2007/2008 with Flex 2 by someone no longer with the company.  It has worked just fine for years, but not anymore.  The application aggregates pricing data over several years, and shows it in