• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a PDF file from NSString without showing it onscreen (solution?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a PDF file from NSString without showing it onscreen (solution?)


  • Subject: Re: Creating a PDF file from NSString without showing it onscreen (solution?)
  • From: Paul Archibald <email@hidden>
  • Date: Tue, 26 Aug 2008 14:47:02 -0700

I think this will probably do:

- (void) renderToPDFFile: (NSString*) text :(NSString*) file {
	NSRect r = NSMakeRect(0, 0, 800, 800);
	NSTextView* v = [[NSTextView alloc] initWithFrame:r];
	[v setHidden:YES];
	[v insertText:text];
	[v sizeToFit];			// ah, the magic elixir!
	r = [v bounds];			// now it is the right size
	NSData *data = [v dataWithPDFInsideRect:r];
	[data writeToFile:file atomically:YES];
	[v release];
}

It seems that the sizeToFit method only effects the width of the view, but that's probably okay in my case. My text will always be fairly narrow, but it could be quite tall.

Guess I better do some error checking.

Also got rid of that redundant stuff that I didn't need because there was already some stuff that could be used.


Paul CROR (Chief Redundancy Officer of Redundancy)



On Aug 26, 2008, at 1:22 PM, Andy Lee wrote:

On Aug 26, 2008, at 4:03 PM, Paul Archibald wrote:
PDFImageView* pdfview = [[PDFImageView alloc] init];

[...], I see that my pdfbounds rectangle is not properly sized, but is just {0,0,0,0}.

That's because you used -init to initialize pdfView. The designated initializer for NSViews is -initWithFrame:.


--Andy



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >Creating a PDF file from NSString without showing it onscreen (From: Paul Archibald <email@hidden>)
 >Re: Creating a PDF file from NSString without showing it onscreen (From: Andy Lee <email@hidden>)

  • Prev by Date: Removing Applications from the Dock Programmatically
  • Next by Date: Re: Removing Applications from the Dock Programmatically
  • Previous by thread: Re: Creating a PDF file from NSString without showing it onscreen
  • Next by thread: Removing Applications from the Dock Programmatically
  • Index(es):
    • Date
    • Thread