Closed TealEgg closed 2 years ago
Hi! Using the DrawGraphics
method is indeed the right thing to do:
// Create the two pages and draw on them.
Page page1 = ...
Page page2 = ...
// Create the final "container" page.
Page finalPage = new Page(100, 100);
// Draw the first page on the container page.
finalPage.Graphics.DrawGraphics(0, 0, page1.Graphics);
// Draw the second page on the container page.
finalPage.Graphics.DrawGraphics(0, 0, page2.Graphics);
To avoid the UnbalancedStackException
, you need to make sure that, for each page, the number of calls to Graphics.Save
and the number of calls to Graphics.Restore
are equal. The message of the exception should tell you which one is in excess.
How do make the number of calls to Save and Restore equal. For me, I have 1 Save and 0 Restores.
Just add a call to Restore
somewhere, or remove the call to Save
(which is doing nothing, if you never call Restore
)!
Okay, now I'm just confused, they are equal, yet it still gives it an error:
Edit: Just when I posted this, I fixed the problem. I was using the graphics of a page to draw graphics instead of creating a new graphics instance. Thanks for the help and sorry for the trouble!
Glad to hear that you got it working! Feel free to reopen this if you're still having issues. Also, if you share your code it might be easier to figure out what is the problem!
Hello, I was just wondering if it is possible to merge pages together, instead of creating a raster image of each page and putting all the images into one page? I want to do this, so the final file can be in svg/pdf format. Thanks in advance! Edit: I also tried using DrawGraphics, but I kept getting a VectSharp.UnbalancedStackException