创建空白的PDF

2018-08-16  本文已影响7人  大牛之路

有时候我们需要创建一块空白的pdf,供用户自己填充内容

-(void)createPDF:(CGSize)size{
//这里我传的是自己的本地路径
  NSString* pdfFileName = [self createPDfPath];
  // 创建一个PDF的上下文,页面大小
  UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
  
  // 标记新页面的开头
  UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, size.width, size.height), nil);
  
  // 获取上下文.
  CGContextRef currentContext = UIGraphicsGetCurrentContext();
  
  // 把文字变成矩阵已知状态。这将确保没有旧缩放因子被留在原处。
  CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
  
  //文本坐标翻转
  CGContextTranslateCTM(currentContext, 0, 100);
  CGContextScaleCTM(currentContext, 1.0, -1.0);
  
  
  //关闭PDF上下文
  UIGraphicsEndPDFContext();
}
上一篇下一篇

猜你喜欢

热点阅读