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

  • 相关阅读:
    scp免密码登陆进行远程文件同步
    MAD(Median absolute deviation, 中位数绝对偏差)
    机器学习之评价准则RoC与PR
    最新HGVS基因突变命名规则速览
    Somatic vs Germline Mutations
    c/c++ 获取文件夹或目录下的文件
    诊断实验评估指标-灵敏度(sensitivity)特异度(specificity)准确度(accuracy)
    互斥量与条件变量(三步走战略)结合使用原理
    linux常用的时间获取函数(time,gettimeofday,clock_gettime,_ftime,localtime,strftime )
    dup和dup2应用实例(dup跟APUE有出入,close+dup=dup2?)
  • 原文地址:https://www.cnblogs.com/rexzhao/p/1769064.html
Copyright © 2011-2022 走看看