/// <summary>Flushes page and its content stream.</summary> /// <remarks> /// Flushes page and its content stream. If <code>flushXObjects</code> is true the images and FormXObjects /// associated with this page will also be flushed. /// <br /> /// For notes about tag structure flushing see /// <see cref="Flush()">PdfPage#flush() method</see> /// . /// <br /> /// <br /> /// If <code>PdfADocument</code> is used, flushing will be applied only if <code>flushXObjects</code> is true. /// </remarks> /// <param name="flushXObjects">if true the images and FormXObjects associated with this page will also be flushed. /// </param> public virtual void Flush(bool flushXObjects) { // TODO log warning in case of failed flush in pdfa document case if (IsFlushed()) { return; } if (GetDocument().IsTagged() && !GetDocument().GetStructTreeRoot().IsFlushed()) { GetDocument().GetTagStructureContext().FlushPageTags(this); GetDocument().GetStructTreeRoot().CreateParentTreeEntryForPage(this); } GetDocument().DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.END_PAGE, this)); if (flushXObjects) { GetDocument().CheckIsoConformance(this, IsoKey.PAGE); } int contentStreamCount = GetContentStreamCount(); for (int i = 0; i < contentStreamCount; i++) { GetContentStream(i).Flush(false); } ICollection <PdfObject> xObjects = null; if (resources != null) { if (resources.IsReadOnly() && !resources.IsModified()) { GetPdfObject().Remove(PdfName.Resources); } else { if (flushXObjects) { PdfDictionary xObjectsDict = GetPdfObject().GetAsDictionary(PdfName.Resources).GetAsDictionary(PdfName.XObject ); xObjects = xObjectsDict != null?xObjectsDict.Values() : null; } } } resources = null; base.Flush(); if (flushXObjects && xObjects != null) { FlushXObjects(xObjects); } }
private bool FlushPage(int pageNum) { PdfPage page = pdfDoc.GetPage(pageNum); if (page.IsFlushed()) { return(false); } bool pageChanged = false; if (!release) { pdfDoc.DispatchEvent(new PdfDocumentEvent(PdfDocumentEvent.END_PAGE, page)); InitCurrentLayers(pdfDoc); } PdfDictionary pageDict = page.GetPdfObject(); // Using PdfPage package internal methods in order to avoid PdfResources initialization: initializing PdfResources // limits processing possibilities only to cases in which resources and specific resource type dictionaries are not flushed. PdfDictionary resourcesDict = page.InitResources(false); // inits /Resources dict entry if not inherited and not created yet PdfResources resources = page.GetResources(false); if (resources != null && resources.IsModified() && !resources.IsReadOnly()) { resourcesDict = resources.GetPdfObject(); pageDict.Put(PdfName.Resources, resources.GetPdfObject()); pageDict.SetModified(); pageChanged = true; } if (!resourcesDict.IsFlushed()) { FlushDictRecursively(resourcesDict, null); FlushOrRelease(resourcesDict); } FlushDictRecursively(pageDict, pageContext); if (release) { if (!page.GetPdfObject().IsModified()) { pdfDoc.GetCatalog().GetPageTree().ReleasePage(pageNum); page.UnsetForbidRelease(); page.GetPdfObject().Release(); } } else { if (pdfDoc.IsTagged() && !pdfDoc.GetStructTreeRoot().IsFlushed()) { page.TryFlushPageTags(); } if (!pdfDoc.IsAppendMode() || page.GetPdfObject().IsModified()) { page.ReleaseInstanceFields(); page.GetPdfObject().Flush(); } else { // it's append mode pdfDoc.GetCatalog().GetPageTree().ReleasePage(pageNum); page.UnsetForbidRelease(); page.GetPdfObject().Release(); } } layersRefs.Clear(); return(pageChanged); }