This is an extract from my WinForms application:
override protected void OnPaint(PaintEventArgs e) { // Create a new PDF document PdfDocument document = new PdfDocument();
// Create an empty page PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromGraphics(e.Graphics, new XSize(100, 100));
// Define transformation for container. Rectangle srcRect = new Rectangle(0, 0, 200, 200); Rectangle destRect = new Rectangle(100, 100, 150, 150);
// Begin graphics container. XGraphicsContainer containerState1 = gfx.BeginContainer( destRect, srcRect, XGraphicsUnit.Point);
// Fill red rectangle in container. gfx.DrawRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200);
// End graphics container. gfx.EndContainer(containerState1);
// Begin graphics container. GraphicsContainer containerState2 = e.Graphics.BeginContainer( destRect, srcRect, GraphicsUnit.Point);
// Fill red rectangle in container. e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 200, 200);
// End graphics container. e.Graphics.EndContainer(containerState2);
// Save the document... const string filename = "C:\\HelloWorld_tempfile.pdf"; document.Save(filename); // ...and start a viewer. //Process.Start(filename); }
Attachments: |
File comment: Black rectangle was drawn by .NET Graphics. Red rectangle was drawn by PdfSharp XGraphics.
PdfSharp.jpg [ 24.51 KiB | Viewed 12615 times ]
|
|