public void AlterContents()
{
if (over == null && under == null)
{
return;
}
PdfArray ar = null;
PdfObject content = PdfReader.GetPdfObject(pageN.Get(PdfName.CONTENTS), pageN);
if (content == null)
{
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
else if (content.IsArray())
{
ar = (PdfArray)content;
}
else if (content.IsStream())
{
ar = new PdfArray();
ar.Add(pageN.Get(PdfName.CONTENTS));
pageN.Put(PdfName.CONTENTS, ar);
}
else
{
ar = new PdfArray();
pageN.Put(PdfName.CONTENTS, ar);
}
ByteBuffer out_p = new ByteBuffer();
if (under != null)
{
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(under.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
}
if (over != null)
{
out_p.Append(PdfContents.SAVESTATE);
}
PdfStream stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(cstp.CompressionLevel);
PdfIndirectReference ref1 = cstp.AddToBody(stream).IndirectReference;
ar.AddFirst(ref1);
out_p.Reset();
if (over != null)
{
out_p.Append(' ');
out_p.Append(PdfContents.RESTORESTATE);
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(over.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(cstp.CompressionLevel);
ar.Add(cstp.AddToBody(stream).IndirectReference);
}
pageN.Put(PdfName.RESOURCES, pageResources.Resources);
}