• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠(yuǎn),我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數(shù)據(jù)加載中……

            IOS 繪制PDF


             1 -(void)createPdf:(UIImage *)img andText:(NSString *)text{
             2     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
             3     NSString *saveDirectory = [paths objectAtIndex:0];
             4     NSString *saveFileName = @"myPDF.pdf";
             5     NSString *newFilePath = [saveDirectory stringByAppendingPathComponent:saveFileName];
             6     const char *filename = [newFilePath UTF8String];
             7     CGRect pageRect = CGRectMake(0, 0, 612, 792);
             8     // This code block sets up our PDF Context so that we can draw to it
             9     
            10     
            11     CGContextRef pdfContext;
            12     CFStringRef path;
            13     CFURLRef url;
            14     CFMutableDictionaryRef myDictionary = NULL;
            15     // Create a CFString from the filename we provide to this method when we call it
            16     path = CFStringCreateWithCString (NULL, filename, kCFStringEncodingUTF8);
            17     // Create a CFURL using the CFString we just defined
            18     url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
            19     CFRelease (path);
            20     // This dictionary contains extra options mostly for ‘signing’ the PDF
            21     myDictionary = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
            22     CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
            23     CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
            24     // Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
            25     pdfContext = CGPDFContextCreateWithURL (url, &pageRect, myDictionary);
            26     // Cleanup our mess
            27     CFRelease(myDictionary);
            28     CFRelease(url);
            29 
            30     // Done creating our PDF Context, now it’s time to draw to it
            31     // Starts our first page
            32     CGContextBeginPage (pdfContext, &pageRect);
            33     
            34     UIImage* myUIImage = img;
            35     CGImageRef pageImage = [myUIImage CGImage];
            36     CGContextDrawImage(pdfContext, CGRectMake(0,0,([myUIImage size].width) , ([myUIImage size].height)), pageImage); //繪制圖片
            37     // Draws a black rectangle around the page inset by 50 on all sides
            38 //    CGContextStrokeRect(pdfContext, CGRectMake(50, 50, pageRect.size.width - 100, pageRect.size.height - 100));
            39     
            40     // Adding some text on top of the image we just added
            41 //    CGContextSelectFont (pdfContext, "Helvetica", 30, kCGEncodingMacRoman);
            42     CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
            43     CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
            44 
            45     
            46 
            47     UIGraphicsPushContext(pdfContext);  //將需要繪制的層push
            48     CGContextTranslateCTM(pdfContext, 0, 792);  //轉(zhuǎn)換Y軸坐標(biāo),  底層坐標(biāo)與cocoa 組件不同 Y軸相反
            49     CGContextScaleCTM(pdfContext, 1, -1);
            50     
            51 //    CGContextShowTextAtPoint (pdfContext, 260, 390, [text UTF8String], strlen([text UTF8String])); //漢字不正常
            52 
            53     [text drawAtPoint:CGPointMake(80, 80) withFont:[UIFont systemFontOfSize:18]];  //繪制漢字
            54 
            55 //    UIFont *font = [UIFont systemFontOfSize:15 ]; //自定義字體
            56 //    CGContextSetFillColorWithColor(pdfContext, [UIColor blackColor].CGColor); //顏色
            57 //    [text drawAtPoint:CGPointMake(260,390) forWidth:50 withFont:font minFontSize:8 actualFontSize:NULL lineBreakMode:UILineBreakModeTailTruncation baselineAdjustment:UIBaselineAdjustmentAlignCenters];
            58     
            59     UIGraphicsPopContext(); 
            60     
            61     
            62     CGContextStrokePath(pdfContext);
            63     
            64     // End text
            65     // We are done drawing to this page, let’s end it
            66     // We could add as many pages as we wanted using CGContextBeginPage/CGContextEndPage
            67     CGContextEndPage (pdfContext);
            68     // We are done with our context now, so we release it
            69     CGContextRelease (pdfContext);
            70 }


            1 - (void)viewDidLoad
            2 {
            3     [super viewDidLoad];
            4     // Do any additional setup after loading the view, typically from a nib.
            5     
            6     //調(diào)用方法
            7     [self createPdf:[UIImage imageNamed:@"aa"] andText:@"漢字"];
            8  
            9 }


            沒注釋掉的代碼 每一行都有其意義. 注意步驟, 仔細(xì)閱讀注釋

            posted on 2013-03-18 23:10 Khan 閱讀(3664) 評論(0)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺開發(fā)

            午夜精品久久久久久久久| 亚洲精品高清一二区久久| 久久久这里有精品中文字幕| 久久婷婷五月综合97色一本一本 | 久久免费国产精品一区二区| 国产精品99久久精品爆乳| 久久精品无码一区二区三区免费 | 久久久久久久尹人综合网亚洲| 久久久久综合网久久| 久久99国产一区二区三区| 狠狠精品久久久无码中文字幕| 久久91精品久久91综合| 亚洲精品tv久久久久| 精品免费久久久久国产一区| 99国内精品久久久久久久| 99久久人妻无码精品系列| 亚洲国产一成久久精品国产成人综合| 色综合久久天天综合| 777久久精品一区二区三区无码| 国产人久久人人人人爽| 伊人久久大香线蕉AV色婷婷色| 四虎国产精品免费久久| 精品久久久久久久国产潘金莲| 久久久久久久久久久精品尤物 | 精品免费久久久久国产一区| 久久99热精品| 久久婷婷五月综合成人D啪| 久久无码国产| 一本色道久久88—综合亚洲精品| 久久久久九九精品影院| 精品久久久久久亚洲精品| 伊人久久大香线蕉亚洲五月天 | 一本久久a久久精品vr综合| 亚洲AV日韩精品久久久久久| 亚洲AV无码久久精品狠狠爱浪潮| 亚洲综合久久综合激情久久| 久久国产三级无码一区二区| 亚洲人成伊人成综合网久久久| 久久99精品久久久久久| 久久免费视频6| 久久精品国产亚洲AV无码麻豆|