Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:13+00:00 2026-06-10T14:26:13+00:00

I have a Printable class named myPrintableObject and print method is over-ridden in following

  • 0

I have a Printable class named myPrintableObject and print method is over-ridden in following manner:

public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
      {
        if(pageIndex<5)
          {
           pf.setOrientation(PageFormat.LANDSCAPE);
           g.drawString("HELLO FRIEND",100,180);
           return PAGE_EXISTS;
          }
        else
          {return NO_SUCH_PAGE;}

     }

I wanted to print multiple pages in landscape orientation in same document. It is printing except the first page. It is always getting printed in portrait orientation.

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:26:15+00:00Added an answer on June 10, 2026 at 2:26 pm

    Here you are:

        PrinterJob job = PrinterJob.getPrinterJob();
        PageFormat pf = job.defaultPage();
        pf.setOrientation(PageFormat.LANDSCAPE);
        job.setPrintable(myPrintableObject, pf);
    

    Working example:

    public class MyPrintable implements Printable {
    
        public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
            if (pageIndex < 5) {
                graphics.drawString("HELLO FRIEND", 100, 180);
                return PAGE_EXISTS;
            } else {
                return NO_SUCH_PAGE;
            }
        }
    
        public static void main(String[] args) {
            PrinterJob job = PrinterJob.getPrinterJob();
            PageFormat pf = job.defaultPage();
            pf.setOrientation(PageFormat.LANDSCAPE);
            job.setPrintable(new MyPrintable(), pf);
    
            boolean ok = job.printDialog();
            if (ok) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    /* The job did not successfully complete */
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets look at the following example: public class BothPaintAndPrintable implements Paintable,Printable{ public void print()
I have a class with a simple System.Drawing.Point (int, int). public class Foo {
Rails 3.0.3 and Ruby 1.9.2 I have the following class class item < ActiveRecord::Base
I have the following models: class MenuItem < ActiveRecord::Base has_one :price, :as => :pricable
have written this little class, which generates a UUID every time an object of
I have a page from which the user will be able to print .
I have to choose a font for a web application that produces a printable
I would like to make a printable version of my web page. I have
I have a script that creates a printable page by copying the HTML across
I have the following html and I am very confused about the following: The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.