NSAttributedText initWithHTML: can you preserving html links
NSAttributedText initWithHTML: can you preserving html links
- Subject: NSAttributedText initWithHTML: can you preserving html links
- From: minapre999 <email@hidden>
- Date: Mon, 24 Apr 2006 21:40:50 +1000
I have some code to convert html into pdf (code below). To do this I
create an NSAttributedString object, using initWithHTML:, put the
attributed string into a NSTextView, then use print objects to print
the pdf to a file. I want to preserve the html links of the original
file, as links in the final pdf document.
The initWithHTML: method does not appear to convert the links into
thean NSLinkAttributeName in the NSAttributedString (even if it did,
I'm not sure if saving the text view as pdf would preserve it).
Does anyone know if cocoa can convert html to pdf, and preserve the
links?
-(void) pdfFromURL: (NSURL*) absoluteURL toPath: (NSString*) pdfPath {
NSError *outError = nil;
NSData *data = [NSData dataWithContentsOfURL: absoluteURL options:
NSMappedRead error: &outError];
NSString *aStr = [[[NSString alloc] initWithData: data encoding:
NSUTF8StringEncoding] autorelease];
NSMutableAttributedString *mAttrStr = [[NSMutableAttributedString
alloc] init];
if(nil != absoluteURL ) {
NSAttributedString *attStr = [[NSAttributedString alloc]
initWithHTML: [absoluteURL resourceDataUsingCache: NO] baseURL:
absoluteURL documentAttributes: nil];
[mAttrStr appendAttributedString: attStr];
[attStr release];
}
[[myTextView textStorage] setAttributedString: mAttrStr];
NSPrintInfo *printInfo = [[[NSPrintInfo sharedPrintInfo] copy]
autorelease];
NSSize A4Size = NSMakeSize(595.0, 842.0) ;
[printInfo setPaperSize: A4Size];
[printInfo setOrientation: NSPortraitOrientation];
[printInfo setJobDisposition: NSPrintSaveJob];
[printInfo setHorizontalPagination: NSAutoPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];
[printInfo setBottomMargin: 12];
[printInfo setTopMargin: 12];
[printInfo setLeftMargin: 12];
[printInfo setRightMargin: 12];
NSMutableDictionary *printDict = [printInfo dictionary];
[printDict setObject: pdfPath forKey: NSPrintSavePath];
[printDict setObject: [NSNumber numberWithBool: YES] forKey:
NSPrintAllPages];
[[NSFileManager defaultManager] removeFileAtPath: pdfPath handler:
nil];
NSPrintOperation *printOperation = [NSPrintOperation
printOperationWithView: myTextView printInfo: printInfo ];
[printOperation setShowPanels: NO];
[printOperation setShowsProgressPanel: YES];
[printOperation runOperation];
}
Send instant messages to your online friends http://au.messenger.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden