How to show and edit existing PDF files in ios application

前端 未结 3 1404
小鲜肉
小鲜肉 2020-12-09 06:46

I do not want to create new PDF file,that I had already done but want to show and edit existing pdf file in iOS through code..

Is this possible or not and if possibl

3条回答
  •  悲哀的现实
    2020-12-09 07:20

    I know its too late for this question, however I'd like to add my solution.

    I am using UIGraphicsBeginPDFContextToFile to generate a PDF file. I've created a class called PDFCreator from base class UIViewController, in that I have two functions like this:

    - (void) beginContextWithFile:(NSString *)filename
    {
        pageSize = CGSizeMake(1024, 1424);
    
        UIGraphicsBeginPDFContextToFile(filename, CGRectZero, nil);
    
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
    
        [self createInitialPart];
    }
    
    - (void) endContext
    {
        UIGraphicsEndPDFContext();
    }
    

    I've created an object of this class in the app delegate file, as it will retain the object until the app terminates (as was my requirement).

    Initially, I am calling beginContextWithFile: and it will create a pdf file in the document directory along with data I am adding through a call to the createInitialPart method.

    At some point later I need to update that file, so I have another method named secondPart though I called it for some more data to append to that file.

    Once I fill I've done with the creation, I need to call endContext of PDFCreator class, that will complete the pdf generation and yes, I will have the updated file.

    This is little tricky and I didn't perform any memory checks though I had the requirement, I found the solution :)

提交回复
热议问题