zoukankan      html  css  js  c++  java
  • ios 代码生成绘制 pdf 小技巧

      绘制的整个过程      

      UIGraphicsBeginPDFPage();//创建一个空白页

       CGContextSetTextMatrix(pdfContext, flip);//为上下文设置仿射矩阵

            CGContextBeginPath(pdfContext); // 打开上下文 开始绘制

     

    CGFloat height=50;

     NSString*  textContent=[NSStringstringWithFormat:@"绘制第一个PDF"];

    NSString *  width=[self getfontwidth:textContent fontsize:20];

      int     font=[UIFontfontWithName:@"Arial-BoldMT"size:20];

    [textContent drawAtPoint:CGPointMake((612-width)/2, height) withFont:font];

     

    //获得字符串宽度

    -(CGFloat)getfont(NSString *)string fontsize:(int)fontsize{

        UIFont *font=[UIFontsystemFontOfSize:fontsize];

        CGSize size=[string sizeWithFont:font];

        return size.width;

    }

    1. 另起一页

     UIGraphicsBeginPDFPage(); // 就ok了

     2. 绘制一条线

            //set the path of the line that we will draw

            //起始点

             CGContextMoveToPoint(pdfContext, 50, height);//当前上下文移动到固定的一点(起始点)

            //结束点

                        CGContextAddLineToPoint(pdfContext, 612-50, height);// 在上下当前图层上下文的坐标点绘制一个直线结束点)

                       //绘制 线

            CGContextStrokePath(pdfContext);

  • 相关阅读:
    序列操作
    上帝造题的七分钟2 / 花神游历各国
    火柴排队
    pair(对组)用法
    线段树
    链上分治
    Rem与Px的转换
    css中单位px和em,rem的区别
    css网页自适应-1
    css网页自适应-2
  • 原文地址:https://www.cnblogs.com/zander/p/2670045.html
Copyright © 2011-2022 走看看