iOS 15 (Beta) PDFKit 'insertPage:atIndex:' issue

Compiled existing app (ObJective-C) with XCode Version 13.0 beta 5 (13A5212g) without any source code changes. Tested on iPhone XR running iOS 15 beta 7(19A5337a) and noticed that the PDFKit Instance Method 'insertPage:atIndex:' generates incorrect results when appending multiple pages from input .pdf files into one consolidated output .pdf.

The resulting output .pdf contains the total number of pages appended. However, all pages following the second page are a copy of the second page.

Compiling the identical app with Xcode Version 12.5.1 (12E507) and running on another iPhone XR with iOS 14.7.1 does work as expected. The app also works as expected on iOS releases prior to version 14.6.

Downloading the app from the App Store and executing it on the Phone with iOS 15(beta) shows the same issue.

Has anyone experienced a similar problem using iOS 15 (beta) and found a solution. Any recommendations, including from Apple, are welcome. Thanks, DJ

Does it occur as well on simulator ? Could you show the code for appending pages, so that we may try to reproduce and confirm ?

Same problem when using simulator. Implemented routines with PDFDocument as well as CGPDFDocumentRef type calls giving the same incorrect results. Here is a subroutine code snippet demonstrating the pdf file appending procedure used in the app. Works on different devices and iOS/iPadOS versions prior to iOS 15 (all beta releases so far).


{

    /*

     'appDelegate.pdfArray' contains entries of file paths for each pdf input file to be appended to the final output pdf located at 'pdfPathOutput'.

     Had all files either pointed to 'NSApplicationSupportDirectory' or 'NSDocumentDirectory'. Outcome is the same.

     */

    NSString *pdfPathOutput = [appDelegate getPDFFileName:YES : LABELFILEDS];     		NSURL *strURLOut = [[NSURL alloc] initFileURLWithPath:pdfPathOutput];

    NSURL *strURLOutInit = [[NSURL alloc] initFileURLWithPath:[appDelegate.pdfArray objectAtIndex:0]];

    //Initializes the new PDF with the first pdf from the path Array

    PDFDocument *newPdfDocument = [[PDFDocument alloc]initWithURL:strURLOutInit];

    // Start append loop with second pdf input file from array

    for(NSInteger jj = 1;jj < [appDelegate.pdfArray count];jj++)

    {

        NSString *source = [appDelegate.pdfArray objectAtIndex:jj];

        NSURL *strURL = [[NSURL alloc] initFileURLWithPath:source];

        PDFDocument *currentPdfDocument = [[PDFDocument alloc] initWithURL:strURL];

        if(currentPdfDocument)

        {

            for(NSInteger kk = 0; kk < currentPdfDocument.pageCount;kk++)

            {

                // Insert page at zero-based pageAtIndex kk

                [newPdfDocument insertPage:[currentPdfDocument pageAtIndex:kk]atIndex:jj];

            }

            [currentPdfDocument release];

        }

        [strURL release];

    }

    [newPdfDocument writeToURL:strURLOut];

    [strURLOut release];

    [newPdfDocument release];

    [strURLOutInit release];

    return pdfPathOutput; //Returns the path of combined pdf result

}

Index of PDFDocument or CGPDFDocument are a bit confusing.

I understand that atIndex in insert for PDFDocument is the new index value.

  • first page is index 0 in a pdf
  • last page is pageCount-1
  • to insert at the end, need to insert atIndex pageCount

So it seems you do not insert anything at page 0 (jj starts at 1) of newPdfDocument ?

I don't understand your comment:

// Insert page at zero-based pageAtIndex kk
[newPdfDocument insertPage:[currentPdfDocument pageAtIndex:kk]atIndex:jj];

In fact, you insert atIndex jj of newPdf, not kk. kk is the index of page to be inserted from currentPdfDocument

Did you swap jj and kk in the above line ?

iOS 15 (Beta) PDFKit 'insertPage:atIndex:' issue
 
 
Q