I'm trying to implement Print Preview functionality, and I'm not sure I understand exactly how Snippet7 works...
Firstly, am I correct in assuming that you are not offering a "Print Preview" option? Rather, when printing is initiated, Print Preview is the default behavior? (Unlike prevalent apps where a user can choose to Print Preview or simply go straight to printing?)
Secondly, can you please explain the creation of the PrintJob in the createShell() method?
printJob = new PrintJob( "Snippet7.java", new Snippet7() ).setMargins( 108 );
What happens when you pass "new Snippet7()" to the PrintJob constructor? The Snippet7 constructor is not implemented, and I don't see how the createPrint() method gets invoked. It's not through the iterator, is it?
Thanks very much.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can go directly to printing using PaperClips.print(PrintJob, PrinterData).
If you made the createPrint() method static, then the following would be equivalent:
printJob = new PrintJob( "Snippet7.java", createPrint() ).setMargins( 108 );
Admittedly the current code is a bit confusing--it seemed like a good idea at the time. :) What is happening is that when PaperClips calls Snippet7.iterator(Device, GC), that method call is delegated to createPrint().iterator(Device, GC).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, but I don't want to go directly to printing...I'd like to implement the Print Preview functionality.
1. I still don't get how the iterator() method gets called. In one of the previous posts, you said it was really unnecessary to implement the Print interface because the iterator() method wasn't getting called anyway. So who invokes the iterator() method in this case?
2. you didn't answer this part - Am I correct in assuming that you are not offering a separate "Print Preview" option? Rather, when printing is initiated, Print Preview is the default behavior? (Unlike prevalent apps where a user can choose to Print Preview or simply go straight to printing?)
Thanks again for your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1. The iterator() is invoked internally by PaperClips to layout a document before printing/previewing. If you're just creating documents and printing them you needn't concern yourself with it. However if you need to print something that PaperClips does not support out of the box, read on. Here is a basic outline of how PaperClips works:
There are three main interfaces upon which all printing and previewing functionality operates: Print, PrintIterator, and PrintPiece.
Print encapsulates printable content. For example, a TextPrint's encapsulates text content, an ImagePrint encapsulates an image, and GridPrint encapsulates all its cells plus rendering of the GridLook.
When you print or preview a PrintJob, PaperClips takes the Print returned from PrintJob.getDocument() and calls iterator(Device, GC) on it to get a PrintIterator instance for the print's content.
PrintIterator's responsibility is to layout the content, given the width and height available on the page. PaperClips calls next(pageWidth, pageHeight) for the top-level PrintIterator until hasNext() == false. Each PrintPiece returned by next() is a full page of content.
PrintPiece's responsibility is to paint itself on a given device using a given GC. It represents a chunk of a Print's content that has been laid out by a PrintIterator.
Coming back to the snippets, specifically:
PaperClips.print(new PrintJob("Snippet7.java", new Snippet7()), printerData);
When you call PaperClips.print, the method invokes Snippet7.iterator(), which just delegates the call to createPrint().iterator(). I only did it this way because I thought the "new Snippet7()" part looked nice. In reality I see I've made it more complicated to people--you're not the first to be confused by it so I plan to stop implementing Print and just change the call to:
2. No, previewing and printing to paper are independent actions. To preview a document, you must create a PrintPreview control and set its printerData and printJob properties. To print a document to paper, you must call PaperClips.print(PrintJob, PrinterData).
Most of the snippets show a print preview, but this is only for user friendliness.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to implement Print Preview functionality, and I'm not sure I understand exactly how Snippet7 works...
Firstly, am I correct in assuming that you are not offering a "Print Preview" option? Rather, when printing is initiated, Print Preview is the default behavior? (Unlike prevalent apps where a user can choose to Print Preview or simply go straight to printing?)
Secondly, can you please explain the creation of the PrintJob in the createShell() method?
printJob = new PrintJob( "Snippet7.java", new Snippet7() ).setMargins( 108 );
What happens when you pass "new Snippet7()" to the PrintJob constructor? The Snippet7 constructor is not implemented, and I don't see how the createPrint() method gets invoked. It's not through the iterator, is it?
Thanks very much.
You can go directly to printing using PaperClips.print(PrintJob, PrinterData).
If you made the createPrint() method static, then the following would be equivalent:
printJob = new PrintJob( "Snippet7.java", createPrint() ).setMargins( 108 );
Admittedly the current code is a bit confusing--it seemed like a good idea at the time. :) What is happening is that when PaperClips calls Snippet7.iterator(Device, GC), that method call is delegated to createPrint().iterator(Device, GC).
Thanks, but I don't want to go directly to printing...I'd like to implement the Print Preview functionality.
1. I still don't get how the iterator() method gets called. In one of the previous posts, you said it was really unnecessary to implement the Print interface because the iterator() method wasn't getting called anyway. So who invokes the iterator() method in this case?
2. you didn't answer this part - Am I correct in assuming that you are not offering a separate "Print Preview" option? Rather, when printing is initiated, Print Preview is the default behavior? (Unlike prevalent apps where a user can choose to Print Preview or simply go straight to printing?)
Thanks again for your help.
1. The iterator() is invoked internally by PaperClips to layout a document before printing/previewing. If you're just creating documents and printing them you needn't concern yourself with it. However if you need to print something that PaperClips does not support out of the box, read on. Here is a basic outline of how PaperClips works:
There are three main interfaces upon which all printing and previewing functionality operates: Print, PrintIterator, and PrintPiece.
Print encapsulates printable content. For example, a TextPrint's encapsulates text content, an ImagePrint encapsulates an image, and GridPrint encapsulates all its cells plus rendering of the GridLook.
When you print or preview a PrintJob, PaperClips takes the Print returned from PrintJob.getDocument() and calls iterator(Device, GC) on it to get a PrintIterator instance for the print's content.
PrintIterator's responsibility is to layout the content, given the width and height available on the page. PaperClips calls next(pageWidth, pageHeight) for the top-level PrintIterator until hasNext() == false. Each PrintPiece returned by next() is a full page of content.
PrintPiece's responsibility is to paint itself on a given device using a given GC. It represents a chunk of a Print's content that has been laid out by a PrintIterator.
Coming back to the snippets, specifically:
PaperClips.print(new PrintJob("Snippet7.java", new Snippet7()), printerData);
When you call PaperClips.print, the method invokes Snippet7.iterator(), which just delegates the call to createPrint().iterator(). I only did it this way because I thought the "new Snippet7()" part looked nice. In reality I see I've made it more complicated to people--you're not the first to be confused by it so I plan to stop implementing Print and just change the call to:
PaperClips.print(new PrintJob("Snippet7.java", createPrint()), printerData);
2. No, previewing and printing to paper are independent actions. To preview a document, you must create a PrintPreview control and set its printerData and printJob properties. To print a document to paper, you must call PaperClips.print(PrintJob, PrinterData).
Most of the snippets show a print preview, but this is only for user friendliness.