Simple PDF generation code not working as intended

Discussion in 'Mac Programming' started by Monaj, Oct 12, 2011.

  1. Monaj macrumors regular

    Joined:
    May 24, 2009
    #1
    Hi all,

    I am trying a simple application to generate pdf from contents in a
    text view.

    I am using below code:
    Code:
    NSPrintInfo *pdfDisplayInfo = [[NSPrintInfo alloc] 
    initWithDictionary:[NSDictionary 
    dictionaryWithObjectsAndKeys:@"YES",NSPrintHeaderAndFooter,nil]]; 
            [pdfDisplayInfo setVerticalPagination:NSAutoPagination]; 
            [pdfDisplayInfo setHorizontalPagination:NSAutoPagination]; 
            [pdfDisplayInfo setVerticallyCentered:NO]; 
            NSFileManager *filemanager = [NSFileManager defaultManager]; 
            NSMutableData *dataObtained = [[NSMutableData alloc] init]; 
            NSPrintOperation *printOperation = [NSPrintOperation PDFOperationWithView:contentView insideRect:[contentView frame] toData:dataObtained printInfo:pdfDisplayInfo]; 
            [printOperation runOperation]; 
            [filemanager createFileAtPath:[@"~/Documents/SamplePrint.pdf" 
    stringByExpandingTildeInPath] contents:dataObtained attributes:nil];
    Problem is:

    Though I have used setVerticalPagination as NSAutoPagination, content
    in pdf generated is not distributed among multiple pages.


    Can anyone suggest me - if I am doing anything wrong or missing
    something?

    Here is the link for, code :
    http://db.tt/L9rM8NU7

    Thanks,
    Monaj
     
  2. Comrade Yeti macrumors newbie

    Joined:
    Nov 3, 2010
    #2
    What is the size of the view you are trying to draw? What page size are you trying to print to?
     
  3. Monaj thread starter macrumors regular

    Joined:
    May 24, 2009
    #3
    Size of the view depends upon content in text view.

    A4 paper size
     

Share This Page