Re: Report printing
Re: Report printing
- Subject: Re: Report printing
- From: Beat Koch <email@hidden>
- Date: Wed, 26 Nov 2003 00:40:07 +0100
What I would do, if I were trying to do this, would be to make
recordView capable of printing itself , using the view from the nib,
for each record, and then for each page draw in printView the PDF
images from each recordView . Instead of inserting the view from the
nib for each record, you would just insert the "printed" image from
each recordView. I believe there is a printing method that allows you
to specify the NSRect in the view for each page, and then the
drawRect: method will be called with each of those rects, so at any
time you will only need to have rendered recordViews stored in memory
for the records that fit on each individual page.
Ok, here's my printView.drawRect method (I omitted the loop to print
all records):
- (void)drawRect:(NSRect)rect
{
NSRect recordFrame;
NSData *pdfData;
NSPDFImageRep *pdfImageRep;
BOOL drawSuccess;
// Set recordView fields (omitted).
pdfData = [recordView dataWithPDFInsideRect:[recordView bounds]];
// Set the record's position, then draw it.
recordFrame = [recordView frame];
recordFrame.origin.y = rect.size.height - recordFrame.size.height;
pdfImageRep = [NSPDFImageRep imageRepWith
Data:pdfData];
drawSuccess = [pdfImageRep drawInRect:headerFrame];
}
Now, during printing, an alert dialog pops up, telling me that the
print operation failed. Debugging shows that the
[recordView dataWithPDFInsideRect:[recordView bounds]]
message fails; I get the following output in the console window:
*** malloc[4379]: Deallocation of a pointer not malloced: 0xbfffcad0;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
2003-11-26 00:05:16.166 PayMaker[4379] PMSessionEndDocumentNoDialog
failed (error code = -30879)
2003-11-26 00:05:16.166 PayMaker[4379] *** -[NSAutoreleasePool
dealloc]: Exception ignored while releasing an object in an autorelease
pool: NSInternalInconsistencyException Failed to end PMPrintContext
I'm stuck at this point. Why does dataWithPDFInsideRect fail within
drawRect? I've tried to put pdfData = [recordView
dataWithPDFInsideRect:[recordView bounds]] into printView's init
method; there it works perfectly, I can later use the pdfData in
drawRect as shown above and the recordView appears on my page as
expected. recordView is not a subview of printView (it does not matter
if it is or not; the error message remains the same).
Thanks for your help!
Beat
>I have to print a report of one or more pages. Each page contains a
>header followed by a variable amount of rectangles which contain the
>data of a record. I've read all the available documentation on
printing
>and I have set up an NSView subclass for printing. According to the
>documentation, I have to implement drawRect to do my output and this
>also works.
>
>Now I'm a bit lazy and I'd prefer to have a graphical tool to layout
>the fields of the header and of the records instead of hard-coding
>every text output. So I have created a nib file which contains small
>custom views, one for the header and one for records. The idea is
that
>my PrintView loads this nib, places the views correctly and they get
>printed automatically when print: is called. In pseudo-code, this is
>what I hope to do:
>
>- - drawRect (of PrintView)
>{
> compute and set the frame of HeaderView
> set text fields of HeaderView with general information
> display HeaderView
>
> for each record that I want to print do
> compute and set the frame of RecordView
> set text fields of RecordView with record information
> display RecordView (by calling -display or by directly calling
>- -drawRect of RecordView)
> end for
>}
>
>I'd like to have only one instance of RecordView which I can reuse as
>many times as necessary in drawRect. Now... If I add HeaderView as
>subview to PrintView, then it really gets printed. If it's not a
>subview of PrintView, no output is generated. Question 1: Why is
this?
>Can I avoid having to attach HeaderView and RecordView to PrintView
and
>still get an output on paper?
>
>Problem 2: The record-displaying part does not work. Only the last
>record at the last position is printed on the page. Do I really have
to
>instantiate RecordView for every record? If so, is there a better way
>to do it than to reload the nib for every new instance? Can I somehow
>copy a view (NSView does not implement the NSCopying protocol, as far
>as I've seen)?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.