On Nov 19, 2009, at 4:37 PM, Chinh Nguyen wrote:

> The conversion to screen coordinates is causing stair stepping in connected 
> lines and other oddities when exporting to PDF.  As a temporary solution 
> until the code is rewritten, I've created a subclass of my view that's sized 
> at the large coordinate space's dimensions specifically for rendering the 
> image to PDF.  However, I can't seem to resize the PDF data down to the more 
> manageable screen view's dimensions when saving to disk.  I've tried creating 
> an NSPDFImageRep from the PDF data and resizing it but it has no effect on 
> the saved to disk image (I guess setSize: does not affect the original data). 
>  What I end up with is a PDF file with large dimensions that overwhelms 
> whatever application I'm placing it into.
> 
> What I ended up doing is creating an NSView subclass that simply draws the 
> PDF at the size I want and returns the PDF data from that.  This works but is 
> there a better way of resizing the dimensions of PDF data or is the size the 
> size that it's generated at and there's no changing it?

A PDF file has a number of rectangles that affect how and where it draws.  I 
would recommend looking at CGPDFContext.  It gives you the ability to specify 
the size of the PDF you are generating.  You would basically use a combination 
of changing the size of the PDF and using a coordinate transformation to scale 
the PDF content to the size that you want.

> Also, I allow the user to export the image as a bitmap and even override the 
> dimensions.  I create an NSImage from the PDF data, resize the NSImage, then 
> save the TIFF representation to the bitmap format I want.  This works in 
> Leopard but no longer works in Snow Leopard.  I read the tech note about 
> changes to NSImage and caching but I had no luck with the different caching 
> methods.  I ended up creating an NSImage at the desired size, locking the 
> focus, drawing the PDF data at the desired size, unlocking the focus, then 
> saving the TIFF representation.  Is there a better way?

Your solution sounds OK.  I tend to work at the CG Layer a lot so personally, I 
would avoid NSImage altogether and drop down to the Core Graphics layer.  I 
would create a block of memory, use CGBitmapContextCreate to create a CG 
context on that bitmap, draw the graphic into that context, construct a CGImage 
and use Image I/O to export the image.  The end result would be similar, but 
I'd have to go through a lot more steps than you did.

> And finally, is there a way to change the resolution of a bitmap from 72dpi 
> to say 300dpi?  My users want to be able to specify the dimensions of the 
> exported bitmap in inches and the resolution.  They want to be able to place 
> their 1800 pixel wide TIFF file into Word and it show up 6 inches wide (@ 
> 300dpi) instead of 25 inches wide (@ 72dpi).  Not a huge deal because I still 
> recommend our users use PDF but some of them have legacy apps that don't 
> support PDF.  The example I was able to find on this created a new 
> NSBitmapImageRep and copied the image data into it and then set the size.

This is one feature that Image I/O allows you to have control over.  As you 
export each image you can provide a dictionary of image attributes, one of 
which is the desired image resolution.

Scott

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to