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
}