Hello!
We found a solution for your problem.
In PdfContent.cs (around line 124) change method
"internal void PreserveGraphicsState()"
like this:
Code:
internal void PreserveGraphicsState()
{
// If a content stream is touched by PDFsharp it is typically because graphical operations are
// prepended or appended. Some nasty PDF tools does not preserve the graphical state correctly.
// Therefore we try to relieve the problem by surrounding the content stream with push/restore
// graphic state operation.
if (this.Stream != null)
{
byte[] value = Stream.Value;
int length = value.Length;
if (length != 0 && ((value[0] != (byte)'q' || value[1] != (byte)'\n')))
{
byte[] newValue = new byte[length + 2 + 3];
newValue[0] = (byte)'q';
newValue[1] = (byte)'\n';
Array.Copy(value, 0, newValue, 2, length);
newValue[length + 2] = (byte)' ';
newValue[length + 3] = (byte)'Q';
newValue[length + 4] = (byte)'\n';
Stream.Value = newValue;
Elements.SetInteger("/Length", Stream.Length);
}
}
}
In file PdfContents.cs (around line 142) change method "void SetModified()" like this:
Code:
else if (count > 1)
{
// Surround content streams with q/Q operations
byte[] value;
int length;
PdfContent content = (PdfContent)((PdfReference)Elements[0]).Value;
if (content != null && content.Stream != null)
{
length = content.Stream.Length;
value = new byte[length + 2];
value[0] = (byte)'q';
value[1] = (byte)'\n';
Array.Copy(content.Stream.Value, 0, value, 2, length);
content.Stream.Value = value;
content.Elements.SetInteger("/Length", length + 2);
}
content = (PdfContent)((PdfReference)Elements[count - 1]).Value;
if (content != null && content.Stream != null)
{
length = content.Stream.Length;
value = new byte[length + 3];
Array.Copy(content.Stream.Value, 0, value, 0, length);
value[length] = (byte)' ';
value[length + 1] = (byte)'Q';
value[length + 2] = (byte)'\n';
content.Stream.Value = value;
content.Elements.SetInteger("/Length", length + 3);
}
}