Skip navigation.
 
mlQuick look preview multipage rich text
FROM : Philip Dow
DATE : Wed Jul 09 04:40:09 2008

Hi all,

I am trying to generate multipage pdf data for display in a quick look 
preview from rich text attributed string data. Attributed strings 
don't know anything about pages, so it seems to me that I'll have to 
go through the OS printing architecture to generate the multipage pdf 
content.

Frustrating thing is, this works if I write the data to a file but not 
if I send it to quicklook. I can generate the pdf data with a custom 
print info specifying the page attributes, but quicklook does not 
display the content as multipage. If I use the same settings but a 
different print operation, writing the data to a temporary file 
instead, I get a correctly paginated document.

Code follows.

I understand that PDF content can be created with CGPDFContextCreate 
and the associated begin and end page calls, but the attributed string 
doesn't know about pages, so that seems like a dead end to me. If 
there's a method for doing it that way, I'm all for switching.

You might also suggest just sending RTF to Quick Look, but I'd like 
the text attachments to display. Converting it to html seems like even 
more work.

===

GenerateMultiPagePDFPreviewForURL(...)

NSAttributedString *attrString = ...;
NSTextView *textView = ... (filled with attrString);

NSMutableData *pdfData = [NSMutableData data];
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
   
[printInfo setPaperSize:NSMakeSize(612,792)];
[printInfo setHorizontalPagination: NSFitPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];

NSPrintOperation *po = [NSPrintOperation PDFOperationWithView:textView
   insideRect:[textView bounds]
   toData:pdfData
   printInfo:printInfo];

[po runOperation];
QLPreviewRequestSetDataRepresentation(preview, (CFDataRef)pdfData, 
kUTTypePDF, NULL);

===

Quicklook does not present a multipage preview with that code. But the 
following code writes a multipage document...

===

NSAttributedString *attrString = ...;
NSTextView *textView = ... (filled with attrString);

NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
NSMutableDictionary *printInfoDict = [NSMutableDictionary 
dictionaryWithDictionary:[printInfo dictionary]];

[printInfoDict setObject:NSPrintSaveJob forKey:NSPrintJobDisposition];
[printInfoDict setObject:@"someLocation.pdf" forKey:NSPrintSavePath];

printInfo = [[NSPrintInfo alloc] initWithDictionary: printInfoDict];
[printInfo setHorizontalPagination: NSFitPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];
   
po  = [NSPrintOperation printOperationWithView:textView 
printInfo:printInfo];
[po setShowPanels:NO];
[po runOperation];

===

In the first case I'm using [NSPrintOperation 
PDFOperationWithView:insideRect:toData:printInfo:] and in the second 
[NSPrintOperation printOperationWithView: printInfo:]. Is the 
PDFOperationWithView method not capable of producing multipage pdf 
data despite the custom printInfo?

~Phil

Related mailsAuthorDate
mlQuick look preview multipage rich text Philip Dow Jul 9, 04:40
mlRe: Quick look preview multipage rich text Julien Jalon Jul 9, 23:54
mlRe: Quick look preview multipage rich text Jean-Daniel Dupas Jul 10, 00:20
mlRe: Quick look preview multipage rich text Jean-Daniel Dupas Jul 10, 00:49
mlRe: Quick look preview multipage rich text Philip Dow Jul 11, 20:00
mlRe: Quick look preview multipage rich text Julien Jalon Jul 11, 22:02
mlRe: Quick look preview multipage rich text -- NSPrintOperation inconsistency Philip Dow Jul 13, 22:48