protected internal void AlterContents()
{
foreach (PageStamp ps in pagesToContent.Values) {
PdfDictionary pageN = ps.pageN;
MarkUsed(pageN);
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;
MarkUsed(ar);
}
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 (ps.under != null) {
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(ps.under.InternalBuffer);
out_p.Append(PdfContents.RESTORESTATE);
}
if (ps.over != null)
out_p.Append(PdfContents.SAVESTATE);
PdfStream stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.AddFirst(AddToBody(stream).IndirectReference);
out_p.Reset();
if (ps.over != null) {
out_p.Append(' ');
out_p.Append(PdfContents.RESTORESTATE);
ByteBuffer buf = ps.over.InternalBuffer;
out_p.Append(buf.Buffer, 0, ps.replacePoint);
out_p.Append(PdfContents.SAVESTATE);
ApplyRotation(pageN, out_p);
out_p.Append(buf.Buffer, ps.replacePoint, buf.Size - ps.replacePoint);
out_p.Append(PdfContents.RESTORESTATE);
stream = new PdfStream(out_p.ToByteArray());
stream.FlateCompress(compressionLevel);
ar.Add(AddToBody(stream).IndirectReference);
}
AlterResources(ps);
}
}