|
31 | 31 | import org.apache.pdfbox.cos.COSArray; |
32 | 32 | import org.apache.pdfbox.cos.COSBase; |
33 | 33 | import org.apache.pdfbox.cos.COSDictionary; |
| 34 | +import org.apache.pdfbox.cos.COSInteger; |
34 | 35 | import org.apache.pdfbox.cos.COSName; |
35 | 36 | import org.apache.pdfbox.cos.COSObject; |
36 | 37 | import org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction; |
@@ -408,23 +409,45 @@ private COSBase createDictionaryClone(COSBase src, COSBase dstParent, COSDiction |
408 | 409 | { |
409 | 410 | return dstDict; |
410 | 411 | } |
| 412 | + COSDictionary srcPageDict = srcDict.getCOSDictionary(COSName.PG); |
411 | 413 | COSDictionary dstPageDict = null; |
412 | | - if (srcDict.containsKey(COSName.PG)) |
| 414 | + COSBase kid = srcDict.getDictionaryObject(COSName.K); |
| 415 | + if (srcPageDict != null) |
413 | 416 | { |
414 | | - COSDictionary srcPageDict = srcDict.getCOSDictionary(COSName.PG); |
415 | | - if (srcPageDict == null) |
416 | | - { |
417 | | - return null; |
418 | | - } |
419 | 417 | dstPageDict = pageDictMap.get(srcPageDict); |
420 | | - if (dstPageDict == null) |
| 418 | + if (dstPageDict != null) |
421 | 419 | { |
422 | | - return null; |
| 420 | + PDPage dstPage = new PDPage(dstPageDict); |
| 421 | + if (dstPageTree.indexOf(dstPage) == -1) |
| 422 | + { |
| 423 | + return null; |
| 424 | + } |
423 | 425 | } |
424 | | - PDPage dstPage = new PDPage(dstPageDict); |
425 | | - if (dstPageTree.indexOf(dstPage) == -1) |
| 426 | + else |
426 | 427 | { |
427 | | - return null; |
| 428 | + // PDFBOX-6009: quit if MCIDs because these need a /Pg entry |
| 429 | + boolean hasMCIDs = false; |
| 430 | + if (kid instanceof COSInteger) |
| 431 | + { |
| 432 | + hasMCIDs = true; |
| 433 | + } |
| 434 | + else if (kid instanceof COSArray) |
| 435 | + { |
| 436 | + COSArray ar = (COSArray) kid; |
| 437 | + for (int i = 0; i < ar.size(); ++i) |
| 438 | + { |
| 439 | + if (ar.getObject(i) instanceof COSInteger) |
| 440 | + { |
| 441 | + hasMCIDs = true; |
| 442 | + break; |
| 443 | + } |
| 444 | + } |
| 445 | + } |
| 446 | + if (hasMCIDs) |
| 447 | + { |
| 448 | + return null; |
| 449 | + } |
| 450 | + // else keep this as an intermediate element for now |
428 | 451 | } |
429 | 452 | } |
430 | 453 |
|
@@ -466,7 +489,6 @@ private COSBase createDictionaryClone(COSBase src, COSBase dstParent, COSDiction |
466 | 489 | } |
467 | 490 |
|
468 | 491 | dstDict.setItem(COSName.PG, dstPageDict); |
469 | | - COSBase kid = srcDict.getDictionaryObject(COSName.K); |
470 | 492 |
|
471 | 493 | // stack overflow here with 207658.pdf, too complex |
472 | 494 | COSBase cloneKid = createClone(kid, dstDict, dstPageDict != null ? dstPageDict : currentPageDict); |
|
0 commit comments