Answered by:
How to print a lot of images. (C# / XAML / Windows Store App)

Question
-
We have made printing application for windows 8 rt. (C# , XAML)
We tried to print 100 images(about 4 GB) but "out of memory" exception occured.
I think all images should be loaded to make PrintDocument, at this time, out of memory exception occurred.
Please Let me know how to print lots of images.
protected override async void AddPrintPages(object sender, AddPagesEventArgs e) { PrintDocument printDoc = (PrintDocument)sender; try { for (int i = 0; i < this.printPagesCount; i++) { UIElement page = null; bool pageReady = false; lock (printSync) { pageReady = pageCollection.TryGetValue(i, out page); } if (!pageReady) { page = await GeneratePage(i + 1, currentPageDescription); } printDoc.AddPage(page); } } catch (Exception ex) { } printDoc.AddPagesComplete(); currentPageDescription = null; }
- Edited by Jhoon Kim Monday, April 29, 2013 12:07 PM
Monday, April 29, 2013 12:03 PM
Answers
-
This is a very bad idea. Store apps compile to 32-bit architecture by default on x86 machines, and ARM supports only 32 bits at all. The highest number available in a 32-bit machine is 4Gb, which is why you are running into OOM. You'll have to figure out how to load a few images at a time, print them, and then garbage collect them.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.- Proposed as answer by sandy purpletalk Tuesday, May 21, 2013 7:18 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, November 4, 2013 1:26 PM
Monday, April 29, 2013 1:47 PMModerator
All replies
-
This is a very bad idea. Store apps compile to 32-bit architecture by default on x86 machines, and ARM supports only 32 bits at all. The highest number available in a 32-bit machine is 4Gb, which is why you are running into OOM. You'll have to figure out how to load a few images at a time, print them, and then garbage collect them.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.- Proposed as answer by sandy purpletalk Tuesday, May 21, 2013 7:18 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, November 4, 2013 1:26 PM
Monday, April 29, 2013 1:47 PMModerator -
In above case, for example, user select 100 images in the app and click print button via charms UI - print devices
In this case, windows store app needs to handle AddPages event of PrintDocument and call AddPagesComplete when all final collection is prepared.
* AddPages Occurs when the PrintManager requests the final collection of pages to send to the printer.
* AddPagesComplete Indicates that the application will not add more pages to the print list, and that the print list is ready to be released.
Question is that, is it possible to divide some group of images and then prepare and print few images of each group instead of handling all selected images that cause out of memory? If it's possible, how to code it? Because AddPages event is only happening one time when firing print so that all images are prepared into final collection.
Tuesday, April 30, 2013 5:19 AM -
Matt,
So the question is in the Windows 8 print architecture how does one send pages one (or a few) at a time when you have a large amount of data to print. Having to store all the data in memory at one time for the entire document seems like a really bad design. Especially if the pages are all images. All the print examples for Windows 8 printing supplied by MS follow this approach.
Michael
Friday, November 1, 2013 6:10 AM -
Well, the samples are just that - not fully-tested production code.
I'm not a printing expert, it seems that you'd want to look into the printing architecture to determine how the printer picks up its jobs and modify your application into working within that architecture. There's a blog post that talks about printing here: http://blogs.msdn.com/b/b8/archive/2012/07/25/simplifying-printing-in-windows-8.aspxThe desktop APIs are here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162861(v=vs.85).aspx
I think that reviewing the desktop functions will give you insight into the bigger picture.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Monday, November 4, 2013 1:35 PMModerator -
Has anyone gotten around this limitation yet using C# and XAML? From the channel 9 video on printing here it even says that to print actual files you should use DirectX and C++.
Monday, August 4, 2014 9:18 PM