private void CopyInheritedProperties(iText.Kernel.Pdf.PdfPage copyPdfPage, PdfDocument pdfDocument) { if (copyPdfPage.GetPdfObject().Get(PdfName.Resources) == null) { PdfObject copyResource = pdfDocument.GetWriter().CopyObject(GetResources().GetPdfObject(), pdfDocument, false ); copyPdfPage.GetPdfObject().Put(PdfName.Resources, copyResource); } if (copyPdfPage.GetPdfObject().Get(PdfName.MediaBox) == null) { copyPdfPage.SetMediaBox(GetMediaBox()); } if (copyPdfPage.GetPdfObject().Get(PdfName.CropBox) == null) { InitParentPages(); PdfArray cropBox = (PdfArray)GetParentValue(parentPages, PdfName.CropBox); if (cropBox != null) { copyPdfPage.SetCropBox(cropBox.ToRectangle()); } } }
/// <summary>Copies page to the specified document.</summary> /// <remarks> /// Copies page to the specified document. /// <br/><br/> /// NOTE: Works only for pages from the document opened in reading mode, otherwise an exception is thrown. /// </remarks> /// <param name="toDocument">a document to copy page to.</param> /// <param name="copier">a copier which bears a specific copy logic. May be NULL</param> /// <returns>copied page.</returns> public virtual iText.Kernel.Pdf.PdfPage CopyTo(PdfDocument toDocument, IPdfPageExtraCopier copier) { PdfDictionary dictionary = GetPdfObject().CopyTo(toDocument, excludedKeys, true); iText.Kernel.Pdf.PdfPage page = new iText.Kernel.Pdf.PdfPage(dictionary); CopyInheritedProperties(page, toDocument); foreach (PdfAnnotation annot in GetAnnotations()) { if (annot.GetSubtype().Equals(PdfName.Link)) { GetDocument().StoreLinkAnnotation(this, (PdfLinkAnnotation)annot); } else { page.AddAnnotation(-1, PdfAnnotation.MakeAnnotation(((PdfDictionary)annot.GetPdfObject().CopyTo(toDocument , false))), false); } } if (toDocument.IsTagged()) { page.structParents = (int)toDocument.GetNextStructParentIndex(); page.GetPdfObject().Put(PdfName.StructParents, new PdfNumber(page.structParents)); } if (copier != null) { copier.Copy(this, page); } else { if (!toDocument.GetWriter().isUserWarnedAboutAcroFormCopying&& GetDocument().GetCatalog().GetPdfObject(). ContainsKey(PdfName.AcroForm)) { ILogger logger = LoggerFactory.GetLogger(typeof(iText.Kernel.Pdf.PdfPage)); logger.Warn(LogMessageConstant.SOURCE_DOCUMENT_HAS_ACROFORM_DICTIONARY); toDocument.GetWriter().isUserWarnedAboutAcroFormCopying = true; } } return(page); }