Examples of PageFormat


Examples of java.awt.print.PageFormat

              status.add(Boolean.FALSE);
            }
          }
          else
          {
            PageFormat pageFormat = printerJob.defaultPage();
            Paper paper = pageFormat.getPaper();
           
            switch (jasperPrint.getOrientationValue())
            {
              case LANDSCAPE :
              {
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
                paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
                paper.setImageableArea(
                  0,
                  0,
                  jasperPrint.getPageHeight(),
                  jasperPrint.getPageWidth()
                  );
                break;
              }
              case PORTRAIT :
              default :
              {
                pageFormat.setOrientation(PageFormat.PORTRAIT);
                paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
                paper.setImageableArea(
                  0,
                  0,
                  jasperPrint.getPageWidth(),
                  jasperPrint.getPageHeight()
                  );
              }
            }
           
            // setting the paper object back as getPaper() returns a clone
            pageFormat.setPaper(paper);
           
            printerJob.setPrintable(this, pageFormat);

            printerJob.print(printRequestAttributeSet);
          }
View Full Code Here

Examples of java.awt.print.PageFormat

    PrinterJob printJob = PrinterJob.getPrinterJob();

    // fix for bug ID 6255588 from Sun bug database
    initPrinterJobFields(printJob);
   
    PageFormat pageFormat = printJob.defaultPage();
    Paper paper = pageFormat.getPaper();

    printJob.setJobName("JasperReports - " + jasperPrint.getName());
   
    switch (jasperPrint.getOrientationValue())
    {
      case LANDSCAPE :
      {
        pageFormat.setOrientation(PageFormat.LANDSCAPE);
        paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
        paper.setImageableArea(
          0,
          0,
          jasperPrint.getPageHeight(),
          jasperPrint.getPageWidth()
          );
        break;
      }
      case
      PORTRAIT :
      default :
      {
        pageFormat.setOrientation(PageFormat.PORTRAIT);
        paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
        paper.setImageableArea(
          0,
          0,
          jasperPrint.getPageWidth(),
          jasperPrint.getPageHeight()
          );
      }
    }

    pageFormat.setPaper(paper);

    Book book = new Book();
    book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
    printJob.setPageable(book);
    try
View Full Code Here

Examples of java.awt.print.PageFormat

        myPreviewContainer = new PreviewContainer();

        PrinterJob prnJob = PrinterJob.getPrinterJob();

        // --
        myPageFormat = new PageFormat();
        myPageFormat.setOrientation(myOrientation);

        myMediaSizeName = DEFAULT_MEDIA_SIZE_NAME;
        MediaSize ms = MediaSize.getMediaSizeForName(myMediaSizeName);
        Paper p = new Paper();
View Full Code Here

Examples of java.awt.print.PageFormat

   * Returns the preferred size of this component according to paper orientation and size
   * of home print attributes.
   */
  @Override
  public Dimension getPreferredSize() {
    PageFormat pageFormat = getPageFormat(this.home.getPrint());
    double maxSize = Math.max(pageFormat.getWidth(), pageFormat.getHeight());
    Insets insets = getInsets();
    return new Dimension((int)(pageFormat.getWidth() / maxSize * 400) + insets.left + insets.right,
        (int)(pageFormat.getHeight() / maxSize * 400) + insets.top + insets.bottom);
  }
View Full Code Here

Examples of java.awt.print.PageFormat

  @Override
  protected void paintComponent(Graphics g) {
    try {
      Graphics2D g2D = (Graphics2D)g.create();
      // Print printable object at component's scale
      PageFormat pageFormat = getPageFormat(this.home.getPrint());
      Insets insets = getInsets();
      double scale = (getWidth() - insets.left - insets.right) / pageFormat.getWidth();
      g2D.scale(scale, scale);
      print(g2D, pageFormat, this.page);
      g2D.dispose();
    } catch (PrinterException ex) {
      throw new RuntimeException(ex);
View Full Code Here

Examples of java.awt.print.PageFormat

  /**
   * Returns the page count of the home printed by this component.
   */
  public int getPageCount() {
    if (this.pageCount == -1) {
      PageFormat pageFormat = getPageFormat(this.home.getPrint());
      BufferedImage dummyImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
      Graphics dummyGraphics = dummyImage.getGraphics();
      // Count pages by printing in a dummy image
      this.pageCount = 0;
      try {
View Full Code Here

Examples of java.awt.print.PageFormat

  public static PageFormat getPageFormat(HomePrint homePrint) {
    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    if (homePrint == null) {
      return printerJob.defaultPage();
    } else {
      PageFormat pageFormat = new PageFormat();
      switch (homePrint.getPaperOrientation()) {
        case PORTRAIT :
          pageFormat.setOrientation(PageFormat.PORTRAIT);
          break;
        case LANDSCAPE :
          pageFormat.setOrientation(PageFormat.LANDSCAPE);
          break;
        case REVERSE_LANDSCAPE :
          pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
          break;
      }
      Paper paper = new Paper();
      paper.setSize(homePrint.getPaperWidth(), homePrint.getPaperHeight());
      paper.setImageableArea(homePrint.getPaperLeftMargin(), homePrint.getPaperTopMargin(),
          homePrint.getPaperWidth() - homePrint.getPaperLeftMargin() - homePrint.getPaperRightMargin(),
          homePrint.getPaperHeight() - homePrint.getPaperTopMargin() - homePrint.getPaperBottomMargin());
      pageFormat.setPaper(paper);
      pageFormat = printerJob.validatePage(pageFormat);
      return pageFormat;
    }
  }
View Full Code Here

Examples of java.awt.print.PageFormat

  /**
   * Writes to <code>outputStream</code> the print of a home in PDF format.
   */
  public void write(OutputStream outputStream) throws IOException {
    PageFormat pageFormat = HomePrintableComponent.getPageFormat(this.home.getPrint());
    Document pdfDocument = new Document(new Rectangle((float)pageFormat.getWidth(), (float)pageFormat.getHeight()));
    try {
      // Get a PDF writer that will write to the given PDF output stream
      PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocument, outputStream);
      pdfDocument.open();
     
      // Set PDF document description
      pdfDocument.addAuthor(System.getProperty("user.name", ""));
      String pdfDocumentCreator = this.preferences.getLocalizedString(
          HomePDFPrinter.class, "pdfDocument.creator");   
      pdfDocument.addCreator(pdfDocumentCreator);
      pdfDocument.addCreationDate();
      String homeName = this.home.getName();
      if (homeName != null) {
        pdfDocument.addTitle(this.controller.getContentManager().getPresentationName(
            homeName, ContentManager.ContentType.PDF));
      }
     
      PdfContentByte pdfContent = pdfWriter.getDirectContent();
      HomePrintableComponent printableComponent =
          new HomePrintableComponent(this.home, this.controller, this.defaultFont);
      // Print each page
      for (int page = 0, pageCount = printableComponent.getPageCount(); page < pageCount; page++) {
        // Check current thread isn't interrupted
        if (Thread.interrupted()) {
          throw new InterruptedIOException();
        }
        PdfTemplate pdfTemplate = pdfContent.createTemplate((float)pageFormat.getWidth(),
            (float)pageFormat.getHeight());
        Graphics g = pdfTemplate.createGraphicsShapes((float)pageFormat.getWidth(),
            (float)pageFormat.getHeight());       
       
        printableComponent.print(g, pageFormat, page);
       
        pdfContent.addTemplate(pdfTemplate, 0, 0);
        g.dispose();
View Full Code Here

Examples of java.awt.print.PageFormat

          // Select Ok option to hide dialog box in Event Dispatch Thread
          pageSetupOptionPane.setValue(JOptionPane.OK_OPTION);
        }
      });
    assertFalse("Page setup dialog still showing", pageSetupDialog.isShowing());
    PageFormat pageFormat = PrinterJob.getPrinterJob().defaultPage();
    // Check home print attributes are modified accordingly
    assertHomePrintEqualPrintAttributes(pageFormat, true, false, true, home);
   
    // 4. Undo changes
    runAction(controller, HomePane.ActionType.UNDO);
View Full Code Here

Examples of java.awt.print.PageFormat

   *    {@link RecorderException RecorderException} exception if print failed
   *    or an {@link InterruptedRecorderException InterruptedRecorderException}
   *    exception if it was interrupted.
   */
  public Callable<Void> showPrintDialog() {
    PageFormat pageFormat = HomePrintableComponent.getPageFormat(this.home.getPrint());
    final PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable(new HomePrintableComponent(this.home, this.controller, getFont()), pageFormat);
    String jobName = this.preferences.getLocalizedString(HomePane.class, "print.jobName");
    if (this.home.getName() != null) {
      jobName += " - " + this.controller.getContentManager().getPresentationName(
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.