Re: REPOST: Lossless PDF scaling
Re: REPOST: Lossless PDF scaling
- Subject: Re: REPOST: Lossless PDF scaling
- From: Kirk Kerekes <email@hidden>
- Date: Mon, 6 May 2002 23:33:50 -0500
On Monday, May 6, 2002, at 03:59 PM, Kirk Kerekes wrote:
Subject: Lossless PDF scaling
[LongWindedQuery omit: forBrevity];
On Monday, May 6, 2002, at 10:27 AM, Christian Brunschen wrote:
Have you investigated NSView:s '- dataWithPDFInRect:(NSRect)rect' method?
The approach would be:
1) Load your original PDF into an NSImage
2) Create an NSView - possibly an NSImageView, or a custom view of your
own - set up to draw _and print_ at the _target_ size you want (let's call
this the 'targetView')
3) Then, NSData *scaledPDFData = [targetView
dataWithPDFInRect:[targetView bounds]];
should basically give you the PDF representing the data inside that
rect, ie, the scaled original PDF.
It was just too simple.
Worked the first time, even though I didn't _exactly_ follow your
prescription. My app already has an off-screen window that I have been
using for various purposes, so I used NSWindow's dataWithPDFInsideRect:
// "os" == "off-screen".
[tImage setSize:inputSize];
[osWindow setContentSize:desiredSize];
// "osImageView is the entire content region of OSWindow,
// and locked to its size.
// Note that NSScaleProportionally doesn't seem to
// work correctly. Go Figure. Should give exactly the same
// results in this code as NSScaleToFit (because the scaling
// is already proportional), but it just fails utterly --
// Image isn't scaled at all, just cropped.
[osImageView setImageScaling:NSScaleToFit];
[osImageView setImage:tImage];
[osWindow display]; // force a rendering to force scaling in tImage
rect = (NSRect){{0.0,0.0},desiredSize};
tData = [osWindow dataWithPDFInsideRect:rect];
[tData writeToFile:outFileName atomically:TRUE];
Thanks Christian!
_______________________________________________
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.