【问题标题】:Implementing an interactive pdf in iOS在 iOS 中实现交互式 pdf
【发布时间】:2012-03-31 07:00:29
【问题描述】:

我必须将一个时间表文件加载到一个 ipad 应用程序中,它是 pdf 或 xls 格式的。加载这些文件(xls/pdf)后,我需要编辑时间表文件中的值并保存。我可以在 UIWebView 中加载这些文件,但我无法编辑这些文件。我需要知道,如何使这些文件(xls/pdf)可编辑?另一个问题是我需要将 pdf 文件转换为 xls 格式,并将 xls 文件从 ipad 应用程序内部转换为 pdf 格式。我希望这很清楚。

【问题讨论】:

    标签: ios


    【解决方案1】:

    如果您想支持编辑,您应该使用 Quartz API 阅读 PDF 文件并将其呈现在您自己的视图中。请参阅以下链接

    Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone?

    PDF editing with iPhone sdk

    http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/10989-pdf-creation-tutorial.html

    这个想法是,如果您只想要文本编辑,使用石英 2D API 读取和绘制 pdf 文件,在可编辑文本元素中显示 pdf 中的所有文本对象,让用户更改并保存在原始 pdf 中创建/替换文本对象使用 Quartz 2D。

    我得到了这段代码来在 pdf 文件中绘制一个文本字符串

    // Create URL for PDF file
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *filename = @"test.pdf";
    NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];
    
    // Create PDF context
    CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef)fileURL, NULL, NULL);
    CGPDFContextBeginPage(pdfContext, NULL);
    UIGraphicsPushContext(pdfContext);
    
    // Flip coordinate system
    CGRect bounds = CGContextGetClipBoundingBox(pdfContext);
    CGContextScaleCTM(pdfContext, 1.0, -1.0);
    CGContextTranslateCTM(pdfContext, 0.0, -bounds.size.height);
    
    // Drawing commands
    [@"Hello World!" drawAtPoint:CGPointMake(100, 100) withFont:[UIFont boldSystemFontOfSize:72.0f]];
    
    // Clean up
    UIGraphicsPopContext();
    CGPDFContextEndPage(pdfContext);
    CGPDFContextClose(pdfContext);
    

    【讨论】:

    • 非常感谢 MSK 斯隆的快速回复。我会尽力按照你告诉我的去做,并让你知道状态。我认为您包含的链接确实是我需要的。再次非常感谢您。在过去的 1 周里,我一直在研究这个主题。我需要在 iOS 中查找、加载和编辑 xls 文件的另一种解决方案。还将pdf转换为xls和xls转换为pdf格式。如果在iOS中无法转换,是否可以在服务器端的帮助下进行。谢谢和问候,Sree。
    • 你需要搜索 ios 的 xls 读/写库。我不知道。查看iphonedevsdk.com/forum/iphone-sdk-development/… 我确信编写自己的(或移植一些现有的)不会是一项艰巨的任务。你也可以移植libxl.com
    • 您好 MSK,您对解析 PDF 数据有任何想法吗?我需要获取 PDF 中的数据。我在谷歌上搜索,但没有找到任何有用的链接。
    • 读取 Quartz API。他们完全支持读取/写入 PDF 文件。
    猜你喜欢
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    相关资源
    最近更新 更多