ipad – 创建多页PDF的错误

ipad – 创建多页PDF的错误,第1张

概述有人已经在iPad应用程序中创建了PDF文档吗?我看到UIKit中有新的功能来执行此 *** 作,但我找不到任何代码示例. BOOL UIGraphicsBeginPDFContextToFile ( NSString *path, CGRect bounds, NSDictionary *documentInfo);void UIGraphicsBeginPDFPage ( 有人已经在iPad应用程序中创建了pdf文档吗?我看到UIKit中有新的功能来执行此 *** 作,但我找不到任何代码示例.

BOol UIGraphicsBeginPdfcontextTofile (   Nsstring *path,CGRect bounds,NSDictionary *documentInfo);voID UIGraphicsBeginpdfpage (   voID);

我找到了一个可以在iPhone上运行的例子,但这给了我错误

Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: CGFont/Freetype: The function `create_subset' is currently unimplemented.Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: invalID Type1 Font: unable to stream Font.Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: FT_Load_Glyph Failed: error 6.Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: FT_Load_Glyph Failed: error 6.Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: FT_Load_Glyph Failed: error 6.Fri Apr 30 11:55:32 wks104.hs.local pdf[1963] <Error>: FT_Load_Glyph Failed: error 6.
解决方法 我实际上通过修改上面的代码来创建多页pdf创建,例如:

- (voID) createpdf:(Nsstring *)filename withContent:(Nsstring *)content forSize:(int)FontSize andFont:(Nsstring *)Font andcolor:(UIcolor *)color {NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);Nsstring *newfilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];CGRect a4Page = CGRectMake(0,DOC_WIDTH,DOC_HEIGHT);NSDictionary *fileMetaData = [[NSDictionary alloc] init];if (!UIGraphicsBeginPdfcontextTofile(newfilePath,a4Page,fileMetaData )) {    NSLog(@"error creating pdf context");    return;}BOol done = NO;CGContextRef context = UIGraphicsGetCurrentContext();CFRange currentRange = CFRangeMake(0,0);CGContextSetTextDrawingMode (context,kCGTextFill);CGContextSelectFont (context,[Font cStringUsingEnCoding:NSUTF8StringEnCoding],FontSize,kCGEnCodingMacRoman);                                                 CGContextSetFillcolorWithcolor(context,[color CGcolor]);// Initialize an attributed string.CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kcfAllocatorDefault,0);CFAttributedStringReplaceString (attrString,currentRange,(CFStringRef)content);// Create the framesetter with the attributed string.CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);do {    UIGraphicsBeginpdfpage();    CGMutablePathref path = CGPathCreateMutable();    CGRect bounds = CGRectMake(left_margin,top_margin,DOC_WIDTH - RIGHT_margin - left_margin,DOC_HEIGHT - top_margin - BottOM_margin);    CGPathAddRect(path,NulL,bounds);    // Create the frame and draw it into the graphics context    CTFrameRef frame = CTFramesetterCreateFrame(framesetter,path,NulL);    if(frame) {        CGContextSaveGState(context);        CGContextTranslateCTM(context,bounds.origin.y);         CGContextScaleCTM(context,1,-1);         CGContextTranslateCTM(context,-(bounds.origin.y + bounds.size.height));         CTFrameDraw(frame,context);        CGContextRestoreGState(context);         // Update the current range based on what was drawn.        currentRange = CTFrameGetVisibleStringRange(frame);        currentRange.location += currentRange.length;        currentRange.length = 0;        CFRelease(frame);           }    // If we're at the end of the text,exit the loop.    if (currentRange.location == CFAttributedStringGetLength((CFAttributedStringRef)attrString))        done = YES;}while(!done);UIGraphicsEndPdfcontext();[fileMetaData release];CFRelease(attrString);CFRelease(framesetter);}

但是,如上所述,它忽略了我尝试设置的字体.我总是得到一些东西,看起来像“Helvetica”.

那么,目前无法在iPad / iPhone上创建pdf文件,嵌入设备上使用的字体?我简直不敢相信.我至少希望那些“通常的嫌疑人”字体,如:CourIEr,Times New Roman等……得到支持.

如果有任何人有关于变通方法的更多信息或有用的提示,欢迎分享.

提前致谢.

总结

以上是内存溢出为你收集整理的ipad – 创建多页PDF的错误全部内容,希望文章能够帮你解决ipad – 创建多页PDF的错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1086140.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存