1. Home
  2. Foxit PDF SDK for iOS
  3. How to print a PDF document using Foxit PDF SDK for iOS?

How to print a PDF document using Foxit PDF SDK for iOS?

Foxit PDF SDK for iOS supports the print feature since version 5.1. You can press the Wireless Print button on the More Menu view in the Complete PDF viewer demo to print the PDF document. Furthermore, you can call the following API to print the PDF documents:

// for iPhone and iTouch
(void)printDoc:(FSPDFDoc *)doc animated:(BOOL)animated jobName:(nullable NSString *)jobName delegate:(nullable id<uiprintinteractioncontrollerdelegate>)delegate completionHandler:(nullable UIPrintInteractionCompletionHandler)completion;
</uiprintinteractioncontrollerdelegate>
// for iPad
(void)printDoc:(FSPDFDoc *)doc fromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated jobName:(nullable NSString *)jobName delegate:(nullable id<uiprintinteractioncontrollerdelegate>)delegate completionHandler:(nullable UIPrintInteractionCompletionHandler)completion;
</uiprintinteractioncontrollerdelegate>

Following is a sample for how to use it:

UIPrintInteractionCompletionHandler completion = ^(UIPrintInteractionController *_Nonnull printInteractionController, BOOL completed, NSError *_Nullable error) {
    if (error) {
       UIAlertAction* action = [UIAlertAction actionWithTitle:[@"Warning:" stringByAppendingString:error.localizedDescription] style:UIAlertActionStyleDefault handler:nil];
       UIAlertController* controller = [[UIAlertController alloc] init];
       [controller addAction:action];
 
       [self showViewController:controller sender:nil];
    }
};
NSString *fileName = @"xxx.pdf";
FSPDFDoc* doc = [[FSPDFDoc alloc] initWithPath:fileName];
[UIExtensionsManager printDoc: doc animated:YES jobName:fileName delegate:nil completionHandler:completion];
Updated on August 29, 2018

Was this article helpful?

Related Articles