Hi guys.......

I have a problem with print all contents of a canvas.
I have set size of the canvas is 100,100 and int this situation when I try to print this will print all the contents.
But if I maximize the frame and then try to print, then some portions are cut from the right side of the canvas.
I want to print it in the A4 size paper.
Suppose the canvas size is smaller than the A4 size paper, then it should print what the size it has, but if it becomes larger size than the A4 paper then it must be re sized to A4 paper and whole the thing over it.

A small example code I have pasted below. So how can I do it?
Thanks.

Java Code:
package Printer;

import java.awt.*;
import java.awt.event.*;

public class PrintingTest extends Frame implements ActionListener {

    PrintCanvas canvas;

    public PrintingTest() {
        super("Printing Test"); 
        canvas = new PrintCanvas();
        add("Center", canvas);
        
        Button b = new Button("Print");
        b.setActionCommand("print");
        b.addActionListener(this);
        add("South", b);

        pack();
    }

    public void actionPerformed(ActionEvent e) {
        String cmd = e.getActionCommand();
        if (cmd.equals("print")) {
            PrintJob pjob = getToolkit().getPrintJob(this, "Printing Test", null, null);

            if (pjob != null) {          
                Graphics pg = pjob.getGraphics();

                if (pg != null) {
                    canvas.printAll(pg);
                    pg.dispose(); // flush page
                }
                pjob.end();

            }
        }
    }

    public static void main(String args[]) {
        PrintingTest test = new PrintingTest();
        test.show();
    }
}

class PrintCanvas extends Canvas {

    public Dimension getPreferredSize() {
        return new Dimension(100, 100);
    }
  
    public void paint(Graphics g) {
        Rectangle r = getBounds();

        g.setColor(Color.yellow);
        g.fillRect(0, 0, r.width, r.height);

        g.setColor(Color.blue);
        g.drawLine(0, 0, r.width, r.height);

        g.setColor(Color.red);
        g.drawLine(0, r.height, r.width, 0);
    }
}