Rank: Member
Groups: Registered
Joined: 6/1/2016(UTC) Posts: 28  Location: Hessen Thanks: 2 times Was thanked: 1 time(s) in 1 post(s)
|
I know I can set the matrix, but when I once set the matrix 0,0,0,0,0,0 I can't change it any more, either with PdfFormObject.Matrix = mymatrix or PdfFormObject.Transform(mymatrix), it will always be 0,0,0,0,0,0. Code:public static void MyMethod(PdfPage page)
{
var elements = FadeOut(page);
//Render page here
FadeIn(page, elements);
}
internal static List<PdfElement> FadeOut(PdfPage page)
{
List<PdfElement> result = new List<PdfElement>();
IEnumerable<PdfFormObject> formObjects = page.PageObjects.OfType<PdfFormObject>();
foreach (PdfFormObject pdfFormObject in formObjects)
{
IntPtr handle = pdfFormObject.Handle;
result.Add(new PdfElement(handle, pdfFormObject.Matrix.Clone()));
pdfPageObject.Transform(0, 0, 0, 0, 0, 0);
}
return result;
}
internal static void FadeIn(PdfPage page, List<PdfElement> fadeInElements)
{
foreach (PdfElement pdfElement in fadeInElements)
{
var pdfFormObject = page.PageObjects.FirstOrDefault(x => x.Handle == pdfElement.Handle) as PdfFormObject;
if (pdfFormObject == null)
{
throw new InvalidOperationException("No element found.");
}
var matrix = pdfElement.Matrix.Clone();
pdfFormObject.Matrix = matrix; //Does not work (pdfFormObject.Matrix = 0,0,0,0,0,0)
pdfFormObject.Transform(matrix); //Does not work (pdfFormObject.Matrix = 0,0,0,0,0,0)
}
}
internal class PdfElement
{
public IntPtr Handle { get; private set; }
public FS_MATRIX Matrix { get; private set; }
public PdfElement(IntPtr handle, FS_MATRIX matrix)
{
Handle = handle;
Matrix = matrix;
}
}
internal static class Extensions
{
public static FS_MATRIX Clone(this FS_MATRIX matrix)
{
return new FS_MATRIX()
{
a = matrix.a,
b = matrix.b,
c = matrix.c,
d = matrix.d,
e = matrix.e,
f = matrix.f,
};
}
}
|