Printing a PDF on iOS
Apryse SDK supports printing. The library handles all the hard work, you simply have to tell it to show the system print dialog with a document. This can be done with [Print.startPrintJob](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/Print.html#startPrintJob(android.content.Context, java.lang.String, com.pdftron.pdf.PDFDoc, java.lang.String, java.lang.Integer, java.lang.Boolean)).
Here is how:
func handlePrintJob(sender: Any?) {
let print = PTPrint()
print.prepareDoc(toPrint: self.pdfDoc, delegate: MyPrintDelegate(self.view), userData: sender)
}- (void)handlePrintJob:(id)sender
{
PTPrint *print = [[PTPrint alloc] init];
[print PrepareDocToPrint:self.pdfDoc Delegate:[[MyPrintDelegate alloc] initWithView:self.view] UserData:sender];
}where MyPrintDelegate is:
class MyPrintDelegate: NSObject, PTPrintDelegate {
let view: UIView
init(_ view: UIView) {
self.view = view
}
func prepared(toPrint docFilePath: String!, userData: Any!) {
let myPrint = PTPrint()
myPrint.printDoc(docFilePath, from: .zero, in: self.view, withJobName: docFilePath, animated: true, completionHandler: nil)
}
}@interface MyPrintDelegate : NSObject <PTPrintDelegate>
- (instancetype)initWithView:(UIView *)view;
@property (nonatomic, strong) UIView *view;
@end
@implementation MyPrintDelegate
- (instancetype)initWithView:(UIView *)view
{
self = [super init];
if (self) {
_view = view;
}
return self;
}
- (void)PreparedToPrint:(NSString *)docFilePath UserData:(id)userData
{
PTPrint *myPrint = [[PTPrint alloc] init];
[myPrint PrintDoc:docFilePath FromRect:CGRectZero InView:self.view WithJobName:docFilePath Animated:YES CompletionHandler:nil];
}
@endLast updated
Was this helpful?