.net - WPF Printing Large Report Causes OutOfMemoryException -
.net - WPF Printing Large Report Causes OutOfMemoryException -
i've created fixeddocument study printed monthly. average 350 pages in length half pages beingness ~200kb jpeg images. study displays nicely in documentviewer, nail problems when attempting print it.
when using
documentviewer1.print()
if seek , print first 3rd of months info eg. 120 pages, works fine. if seek whole month, @ 160th page next error
system.outofmemoryexception: insufficient memory go on execution of program. @ system.windows.media.imaging.bitmapsource.criticalcopypixels(int32rect sourcerect, intptr buffer, int32 buffersize, int32 stride) @ system.windows.media.imaging.bitmapsource.criticalcopypixels(int32rect sourcerect, array pixels, int32 stride, int32 offset) @ microsoft.internal.gdiexporter.cgdibitmap.load(bitmapsource pbitmap, byte[] buffer, pixelformat loadformat) @ microsoft.internal.gdiexporter.cgdirendertarget.drawbitmap(bitmapsource pimage, byte[] buffer, rect rectdest) @ microsoft.internal.gdiexporter.cgdirendertarget.drawimage(bitmapsource source, byte[] buffer, rect rect) @ microsoft.internal.alphaflattener.brushproxydecomposer.microsoft.internal.al phaflattener.iproxydrawingcontext.drawimage(imageproxy image, rect dest, geometry clip, matrix trans) @ microsoft.internal.alphaflattener.primitiverenderer.renderimage(imageproxy image, rect dest, geometry bounds, boolean cliptobounds, int32 start, matrix trans, string desp) @ microsoft.internal.alphaflattener.primitiverenderer.renderimage(imageproxy image, rect dest, geometry clip, matrix trans, string desp) @ microsoft.internal.alphaflattener.flattener.alpharender(primitive primitive, list`1 overlapping, int32 overlaphastransparency, boolean disjoint, string desp) @ microsoft.internal.alphaflattener.flattener.alphaflatten(iproxydrawingcontex t dc, boolean disjoint) @ microsoft.internal.alphaflattener.flattener.convert(primitive tree, ilegacydevice dc, double width, double height, double dpix, double dpiy, nullable`1 quality) @ microsoft.internal.alphaflattener.metrodevice0.flushpage(ilegacydevice sink, double width, double height, nullable`1 outputquality) @ microsoft.internal.alphaflattener.metrotogdiconverter.flushpage() @ system.windows.xps.serialization.ngcserializationmanagerasync.endpage() @ system.windows.xps.serialization.ngcfixedpageserializerasync.endpersistobjec tdata(boolean ismanualstartdoc) @ system.windows.xps.serialization.ngcfixedpageserializerasync.asyncoperation( ngcserializercontext context) @ system.windows.xps.serialization.ngcserializationmanagerasync.invokesaveasxa mlworkitem(object arg) @ system.windows.threading.exceptionwrapper.internalrealcall(delegate callback, object args, int32 numargs) @ ms.internal.threading.exceptionfilterhelper.trycatchwhen(object source, delegate method, object args, int32 numargs, delegate catchhandler) @ system.windows.threading.dispatcheroperation.invokeimpl() @ system.windows.threading.dispatcheroperation.invokeinsecuritycontext(object state) @ system.threading.executioncontext.runtrycode(object userdata) @ system.runtime.compilerservices.runtimehelpers.executecodewithguaranteedclea nup(trycode code, cleanupcode backoutcode, object userdata) @ system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state, boolean ignoresyncctx) @ system.threading.executioncontext.run(executioncontext executioncontext, contextcallback callback, object state) @ system.windows.threading.dispatcheroperation.invoke() @ system.windows.threading.dispatcher.processqueue() @ system.windows.threading.dispatcher.wndprochook(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndwrapper.wndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam, boolean& handled) @ ms.win32.hwndsubclass.dispatchercallbackoperation(object o) @ system.windows.threading.exceptionwrapper.internalrealcall(delegate callback, object args, int32 numargs) @ ms.internal.threading.exceptionfilterhelper.trycatchwhen(object source, delegate method, object args, int32 numargs, delegate catchhandler) @ system.windows.threading.dispatcher.invokeimpl(dispatcherpriority priority, timespan timeout, delegate method, object args, int32 numargs) @ ms.win32.hwndsubclass.subclasswndproc(intptr hwnd, int32 msg, intptr wparam, intptr lparam) @ system.windows.forms.unsafenativemethods.dispatchmessagew(msg& msg) @ system.windows.forms.application.componentmanager.system.windows.forms.unsaf enativemethods.imsocomponentmanager.fpushmessageloop(intptr dwcomponentid, int32 reason, int32 pvloopdata) @ system.windows.forms.application.threadcontext.runmessageloopinner(int32 reason, applicationcontext context) @ system.windows.forms.application.threadcontext.runmessageloop(int32 reason, applicationcontext context) @ system.windows.forms.application.run(applicationcontext context) @ microsoft.visualbasic.applicationservices.windowsformsapplicationbase.onrun( ) @ microsoft.visualbasic.applicationservices.windowsformsapplicationbase.doappl icationmodel()
i thought i'd outsmart printing 30 pages @ time splitting document little 30 page documents using:
dim dlg = new printdialog() if dlg.showdialog() = true dim pagecounter int32 = 0 dim listofdocs new list(of fixeddocument) dim currentfixeddoc new fixeddocument each fixedsizepag fixedpage in printlistofpages dim fixedsizedpageconten pagecontent = new pagecontent ctype(fixedsizedpageconten, iaddchild).addchild(fixedsizepag) currentfixeddoc.pages.add(fixedsizedpageconten) pagecounter = pagecounter + 1 if pagecounter >= 30 listofdocs.add(currentfixeddoc) pagecounter = 0 currentfixeddoc = new fixeddocument end if next if currentfixeddoc.pages.count > 0 listofdocs.add(currentfixeddoc) end if each docum in listofdocs dlg.printdocument(docum.documentpaginator, "testing - part " & (listofdocs.indexof(docum) + 1) & " of " & listofdocs.count) next end if
but caused same error. i've tried printing hundred pages midpoint , towards end of month , works, must volume of pages rather particular image(images jpegs 1 source, max size 400kb).
watching amount of memory beingness used while printing 30 pages @ time see
start = 96mb 30 pages = 367mb 60 pages = 588mb 90 pages = 825mb 120 pages = 1003mb 150 pages = 1238mb
then crashes on next batch @ 1281mb
i've tested on real printer , xps windows printer. when noted downwards memory values, waited until each section had spooled , printed.
i can't understand why building when i'm splitting them separate individual documents. must have dispose i'm not sure what?
you should generate 10 pages per file (a fixeddocument per file), merge these files 1 (you have fixeddocumentsequence). next print on fixeddocumentsequence. sure solution consumes no much memory.
system.windows.xps.xpsdocumentwriter.write(system.windows.documents.fixeddocumentsequence fixeddocumentsequence)
.net wpf printing pagination fixeddocument
Comments
Post a Comment