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?

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");
        add("South", b);


    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) {
                    pg.dispose(); // flush page


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

class PrintCanvas extends Canvas {

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

        g.fillRect(0, 0, r.width, r.height);

        g.drawLine(0, 0, r.width, r.height);

        g.drawLine(0, r.height, r.width, 0);