zoukankan      html  css  js  c++  java
  • create pdf

    I have a block of code that creates a PDF just fine - all works great in all SDK before 3.2. When I use 3.2, either the simulator or a device. The PDF is still created fine and displays in Preview fine, but when you open it with Acrobat it complains of a missing embedded font - whatever font you use... In my main case - it is just Times New Roman.

    I have collapsed the code down to a single text block - same issue....

    Any help is appreciated!!
    CGContextRef pdfContext;
    CFStringRef path;
    CFURLRef url;
    CFMutableDictionaryRef myDictionary = NULL;

    // Create a CFString from the filename we provide to this method when we call it
    path = CFStringCreateWithCString (NULL,"as123.pdf", kCFStringEncodingUTF8);
    // Create a CFURL using the CFString we just defined
    url = CFURLCreateWithFileSystemPath (NULL, path,
    kCFURLPOSIXPathStyle, 0);
    CFRelease (path);
    // Create our PDF Context with the CFURL, the CGRect we provide, and the above defined dictionary
    pageRect=CGRectMake(0,0, 500, 500);
    pdfContext = CGPDFContextCreateWithURL (url, &pageRect, nil);
    // Cleanup our mess
    CFRelease(myDictionary);
    CFRelease(url);
    // Done creating our PDF Context, now it's time to draw to it

    // Starts our first page
    CGContextBeginPage (pdfContext, &pageRect);

    CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
    CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
    //CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
    CGContextSelectFont (pdfContext, "Times New Roman", 14, kCGEncodingMacRoman);

    int _myIndent = 80.0;

    CGContextSetRGBStrokeColor(pdfContext, 0.5, 0.5, 0.5, 1);
    CGContextStrokeRect(pdfContext, CGRectMake(_myIndent, pageRect.size.height-260, (pageRect.size.width - (_myIndent*2)), 1));
    CGContextStrokeRect(pdfContext, CGRectMake(_myIndent, pageRect.size.height-195, (pageRect.size.width - (_myIndent*2)), 1));

    // since the pdf and the NS stuff are flipped -- do that before you set this as the context...
    CGAffineTransform flip=CGAffineTransformMake(1,0,0,-1,0,pageRect.size.height);
    CGContextConcatCTM(pdfContext, flip);
    UIGraphicsPushContext(pdfContext);
    //NSArray *curFonts = [UIFont fontNamesForFamilyName:@"Times New Roman"];
    UIFont* font = [UIFont fontWithName:@"TimesNewRomanPSMT" size:14];

    CGContextSelectFont (pdfContext, "Times New Roman", 14, kCGEncodingMacRoman);
    NSString *officeName = [[NSUserDefaults standardUserDefaults] stringForKey:@"p_practice_name"];
    [officeName drawInRect: CGRectMake(_myIndent, 70, (pageRect.size.width-(_myIndent*2)), 600) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

    UIGraphicsPopContext();

    // We are done drawing to this page, let's end it
    // We could add as many pages as we wanted using CGContextBeginPage/CGContextEndPage
    CGContextEndPage (pdfContext);
    // We are done with our context now, so we release it

    CGContextRelease (pdfContext);

    from:http://www.iphonedevsdk.com/forum/iphone-sdk-development/46787-embed-font-pdf-3-2-sdk.html

  • 相关阅读:
    网页返回码大全
    求数组中子数组的最大和
    什么是面向对象?面向对象与面向过程的区别?
    Java内部类
    Java拆箱装箱
    linux中su和sudo区别
    Linux 中账户管理
    解决warn appiumdoctor bin directory for $java_home is not set
    Moco之include
    Mock server 之 Moco的使用
  • 原文地址:https://www.cnblogs.com/rexzhao/p/1769064.html
Copyright © 2011-2022 走看看