Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:50:43+00:00 2026-06-01T14:50:43+00:00

I m New to the iPhone development and i need to print UIView. so

  • 0

I m New to the iPhone development and i need to print UIView. so i converted UIView into PDF and it work fine for me..
but i don’t know how to pass this PDF to Printer so that it print, can any one help in solving this

Thanks in advance

my code is:

- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
    NSMutableData *pdfData = [NSMutableData data];
    UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
    UIGraphicsBeginPDFPage();
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();
    [aView.layer renderInContext:pdfContext];
    UIGraphicsEndPDFContext();
       NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
    [pdfData writeToFile:documentDirectoryFilename atomically:YES];
    NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

-(void)getPDF{
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
     NSString *documentsPath = [paths objectAtIndex:0]; 
     NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPdf"];
     NSLog(@"filePath: %@",filePath);

     NSData *pngData = [NSData dataWithContentsOfFile:filePath];
    [displayPDFView loadData:pngData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
    [self.view setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.0]];
    displayPDFView.hidden = NO;

}

// printer Code

NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"png"];
    NSData *dataFromPath = [NSData dataWithContentsOfFile:path];

    UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];

    if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {

        printController.delegate = self;

        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        printInfo.outputType = UIPrintInfoOutputGeneral;
        printInfo.jobName = [path lastPathComponent];
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        printController.printInfo = printInfo;
        printController.showsPageRange = YES;
        printController.printingItem = dataFromPath;

        void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
            if (!completed && error) {
                NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
            }
        };

        [printController presentFromRect:btnPrint.frame inView:btnPrint.superview
                                animated:YES completionHandler:completionHandler];
    } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:50:45+00:00Added an answer on June 1, 2026 at 2:50 pm

    You can print pdf by this code….

     #if (READER_ENABLE_PRINT == TRUE) // Option
    
    Class printInteractionController = NSClassFromString(@"UIPrintInteractionController");
    
    if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable])
    {
        NSURL *fileURL = document.fileURL; // Document file URL
    
        printInteraction = [printInteractionController sharedPrintController];
    
        if ([printInteractionController canPrintURL:fileURL] == YES)
        {
            UIPrintInfo *printInfo = [NSClassFromString(@"UIPrintInfo") printInfo];
    
            printInfo.duplex = UIPrintInfoDuplexLongEdge;
            printInfo.outputType = UIPrintInfoOutputGeneral;
            printInfo.jobName = document.fileName;
    
            printInteraction.printInfo = printInfo;
            printInteraction.printingItem = fileURL;
            printInteraction.showsPageRange = YES;
    
            [printInteraction presentFromRect:button.bounds inView:button animated:YES completionHandler:
                ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
                {
                    #ifdef DEBUG
                        if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
                    #endif
                }
            ];
        }
    }
    
      #endif //
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi every body i am new in iPhone application development. In my application need
I'm quite new in iPhone development and I need to develop an app. I
I m new to iphone app development and i need some help. I have
I am new in iPhone development. I need your help in sorting NSArray. in
I am new to iPhone development, I need to play videos which are on
I'm new to iPhone development, I need help. I want to download an XML
New to iPhone development, but I've been given a big project as a first
I'm new in iPhone Development. I'm creating an application in which i need to
I am new to iPhone development. I have a application in which i need
I am really new to iPhone development and I need help setting up my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.