Creating PDF from a view with custom bounds
Creating PDF from a view with custom bounds
- Subject: Creating PDF from a view with custom bounds
- From: email@hidden
- Date: Wed, 18 Jul 2001 21:54:40 +0200
I have a progblem while creating a PDF file from a view. I copied the code
from the example code (see below the method used in my view). This
actually creates a PDF file, but only with a part of the view.
It turns out that my view has custom bounds (something like
[-1,-1]x[2,2]); it is important for the app to keep these bounds as they
are. But when the PDF is created, it seems to put the point (0,0), which
is basically the center of the view, in the lower left corner of the PDF.
So I have only about 1/4 of the view -- even though the size of the PDF
representation is the same as the size of the view. This look like my
drawing have moved to the left and bottom...
So how is it possible to have the PDF representation correctly located?
Here is my code:
-(NSData*) PDFRepresentation {
NSRect frame = [self frame], bounds= [self bounds],
r =NSMakeRect(0.0, 0.0, 2*NSMaxX(frame), 2*NSMaxY(frame));
NSMutableData *pdfData = [[NSMutableData allocWithZone:[self zone]]
init];
NSPrintOperation *printOp;
NSLog(@"%@ PDFRepresentation, frame = %@, bounds = %@, r = %@", self,
NSStringFromRect(frame), NSStringFromRect(bounds), NSStringFromRect(r));
printOp = [NSPrintOperation PDFOperationWithView:self insideRect:r
to
Data:pdfData];
[printOp setShowPanels:NO];
if ([printOp runOperation]) {
NSLog(@"%@ PDFRepresentation: Ok.", self);
[pdfData autorelease];
} else {
NSLog(@"%@ PDFRepresentation: FAILED.", self);
[pdfData release];
pdfData = nil;
}
return pdfData;
}
Thomas Lachand-Robert
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.