public override bool NewPage()
{
FlushFloatingElements();
lastElementType = -1;
if (PageEmpty) {
SetNewPageSizeAndMargins();
return false;
}
if (!open || close) {
throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
}
IPdfPageEvent pageEvent = writer.PageEvent;
if (pageEvent != null)
pageEvent.OnEndPage(writer, this);
//Added to inform any listeners that we are moving to a new page (added by David Freels)
base.NewPage();
// the following 2 lines were added by Pelikan Stephan
indentation.imageIndentLeft = 0;
indentation.imageIndentRight = 0;
// we flush the arraylist with recently written lines
FlushLines();
// we prepare the elements of the page dictionary
// [U1] page size and rotation
int rotation = pageSize.Rotation;
// [C10]
if (writer.IsPdfIso()) {
if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
if (thisBoxSize.ContainsKey("crop"))
thisBoxSize["trim"] = thisBoxSize["crop"];
else
thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
}
}
// [M1]
pageResources.AddDefaultColorDiff(writer.DefaultColorspace);
if (writer.RgbTransparencyBlending) {
PdfDictionary dcs = new PdfDictionary();
dcs.Put(PdfName.CS, PdfName.DEVICERGB);
pageResources.AddDefaultColorDiff(dcs);
}
PdfDictionary resources = pageResources.Resources;
// we create the page dictionary
PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
page.Put(PdfName.TABS, writer.Tabs);
page.Merge(writer.PageDictEntries);
writer.ResetPageDictEntries();
// we complete the page dictionary
// [U3] page actions: additional actions
if (pageAA != null) {
page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
pageAA = null;
}
// [C5] and [C8] we add the annotations
if (annotationsImp.HasUnusedAnnotations()) {
PdfArray array = annotationsImp.RotateAnnotations(writer, pageSize);
if (array.Size != 0)
page.Put(PdfName.ANNOTS, array);
}
// [F12] we add tag info
if (writer.IsTagged())
page.Put(PdfName.STRUCTPARENTS, new PdfNumber(writer.CurrentPageNumber - 1));
if (text.Size > textEmptySize || !UseSeparateCanvasesForTextAndGraphics)
text.EndText();
else
text = null;
IList<IList<IElement>> mcBlocks = new List<IList<IElement>>();
mcBlocks.Add(null);
mcBlocks.Add(null);
mcBlocks.Add(null);
mcBlocks.Add(null);
mcBlocks[0] = writer.DirectContentUnder.SaveMCBlocks();
if (graphics != null)
mcBlocks[1] = graphics.SaveMCBlocks();
if (UseSeparateCanvasesForTextAndGraphics && text != null)
mcBlocks[2] = text.SaveMCBlocks();
mcBlocks[3] = writer.DirectContent.SaveMCBlocks();
writer.Add(page, new PdfContents(writer.DirectContentUnder, graphics, UseSeparateCanvasesForTextAndGraphics ? text : null, writer.DirectContent, pageSize));
// we initialize the new page
InitPage();
writer.DirectContentUnder.RestoreMCBlocks(mcBlocks[0]);
if (graphics != null)
graphics.RestoreMCBlocks(mcBlocks[1]);
if (UseSeparateCanvasesForTextAndGraphics && text != null)
text.RestoreMCBlocks(mcBlocks[2]);
writer.DirectContent.RestoreMCBlocks(mcBlocks[3]);
return true;
}