这里我打印尺寸为'pageSize = CGSizeMake(640,832);'的pdf。这个尺寸大于A4尺寸的页面。所以我会切断一些文字(意味着它不会打印整页)。
在使用MAC打印相同的pdf时,它将在选项的帮助下打印整页(缩放以适合)。所以任何人都可以帮助我摆脱这个问题..在IOS sdk中是否有任何选项可以适应规模。
这是我的代码..
-(void)printItem
{
NSArray *aArrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
NSString *aStr = [[aArrPaths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"PropertyReport_%d.pdf",self.propertyId]];
// NSString *aStr = [[NSBundle mainBundle] pathForResource:@"TRADUZIONE HELP SECTIONS REV2" ofType:@"pdf"];
NSURL *url=[[NSURL alloc] initFileURLWithPath:aStr];
NSData *data=[[NSData alloc] initWithContentsOfURL:url];
printController = [UIPrintInteractionController sharedPrintController];
if(printController && [UIPrintInteractionController canPrintData:data])
{
printController.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
//printInfo.jobName = [NSString stringWithFormat:@"New Image"];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
printController.printInfo = printInfo;
printController.showsPageRange = YES;
printController.printingItem = data;
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);
}
};
// aWebViewPDF.hidden=FALSE;
[printController presentAnimated:YES completionHandler:completionHandler];
}
}
谢谢!
答案 0 :(得分:2)
听起来很奇怪:
printController.showsPageRange = NO;
这似乎启用了自动缩放,但有时会在作业结束时打印一个额外的空白页。 AirPrint基本上就是巫术。
答案 1 :(得分:0)
从PDF的所有页面到scale down
的{{1}}只有一个选项,然后打印出来。我已经完成了ratio
的所有页面,并将其缩小到要求:
printed format
添加所有三种方法:
pdf into images
NSString *strFilePath = [[NSBundle mainBundle] pathForResource:@"pdftouch" ofType:@"pdf"];
pic.printingItems = [[self allPagesImageFromPDF:strFilePath] copy];
Convert all PDF pages into UIImages
-(NSMutableArray *)allPagesImageFromPDF:(NSString *)strPath
{
NSMutableArray *arrImages = [NSMutableArray array];
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:strPath]);
NSInteger numberOfPages = CGPDFDocumentGetNumberOfPages(pdf);
for (NSInteger pageIndex = 1; pageIndex <= numberOfPages;
pageIndex++)
{
UIImage *img = [self getThumbForPage:pdf pageIndex:pageIndex];
[arrImages addObject:[self resizedImage:img]];
}
return arrImages;
}
Resize images
-(UIImage *)resizedImage:(UIImage *)image
{
UIGraphicsBeginImageContext(CGSizeMake(612, 792)); //A4 size
[image drawInRect:CGRectMake(0,0,612, 792)]; //A4 size
UIImage *resizedImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resizedImg;
}
编辑:请参阅printing-uiimage-using-airprint-causes-cut-off-content