Tip: Use SaveDC / RestoreDC

[Top]  [Chapter]  [Previous]  [Next]

Please note - PDF does not offer a possibility to reset the current coordinate transformation. So our PDF engine has to create a complicated  conversation vector to reset to default, in case your programming code demands it. This conversion vector seems to make Acrobat 5 trouble if also a rotation is involved.

 

So we recommend to use SaveDC / RestoreDC, it is available in .NET as Graphics.Save and Graphics.Restore

 

Example:

 

void DrawSomething(Graphics g, ....)

{

           System.Drawing.Drawing2D.GraphicsState saved = g.Save();//= SaveDC

          try

           {  

 

            ...

 

              // not required since we use RestoreDC:

             // g.ResetTransform();

               // g.PageUnit = OrigGraphicsUnit;

           }

          catch (Exception ex)

           {

              MessageBox.Show(ex.Message);

           }

          finally

           {

              g.Restore(saved);// = RestoreDC

           }

       }

}

 

SaveDC / RestoreDC is also useful when working with clipping rectangles. It is not required for the Clipping Paths which make their own brackets.


[tip_use_save_restore.htm]    Copyright © 2007 by WPCubed GmbH