PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat May 11, 2024 10:11 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Mar 02, 2015 8:50 am 
Offline

Joined: Fri Sep 06, 2013 7:01 am
Posts: 27
Location: Cologne, Germany
Dear community.
We uses PdfSharp – library in our application. For output some data as pdf.
In some cases if pdf-document contain many objects PdfSharp throw OutOufMemoryException during saving of pdf-file.
Here is my example-code
Code:
PdfSharp.Pdf.PdfDocument xDoc = new PdfSharp.Pdf.PdfDocument();
            xDoc.Pages.Add(new PdfSharp.Pdf.PdfPage() { Width = 500, Height = 750 });

            xDoc.Info.Author = "Autor";
            xDoc.Info.CreationDate = DateTime.Now;
            xDoc.Info.Creator = "Creator";
            xDoc.Info.Keywords = "KW1, KW2, KW3";
            xDoc.Info.Subject = "Subject";
            xDoc.Info.Title = "Title";

            PdfSharp.Pdf.PdfPage xPage = xDoc.Pages[0];

            PdfSharp.Pdf.Advanced.PdfResources rsx = xPage.GetResources();

            PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(xPage);
            PdfSharp.Drawing.XPen pen = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColor.FromKnownColor(KnownColor.Red));
           
            ////Lines
            pen.LineCap = PdfSharp.Drawing.XLineCap.Round;

            int hLinesCount = 6104000;
            int vLinesCount = 4096000;
           
            int ii = 0;
            for (int i = 0; i < hLinesCount; i++)
            {
                ii = (ii < 750) ? ii + 2 : 0;
                System.Drawing.PointF p0 = new PointF(0, ii);
                System.Drawing.PointF p1 = new PointF(500, ii);
                gfx.DrawLine(pen, p0, p1);
            }

            ii = 0;
            for (int i = 0; i < vLinesCount; i++)
            {
                ii = (ii < 500) ? ii + 2 : 0;
                System.Drawing.PointF p0 = new PointF(ii, 0);
                System.Drawing.PointF p1 = new PointF(ii, 750);
                gfx.DrawLine(pen, p0, p1);
            }
           
            ////Lines--//

            xDoc.PageLayout = PdfSharp.Pdf.PdfPageLayout.SinglePage;
            xDoc.Save(fileFN); ///Here is exception!!!!!!!!!
            xDoc.Close();


How to solve I this problem?
Thanks in advance


Top
 Profile  
Reply with quote  
PostPosted: Mon Mar 02, 2015 4:59 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Hi!

Do you need so many objects on a single page? If so, add more RAM and run the application in 64-bit mode.

If your document has many pages, you can try to create it in smaller chunks (10 or 100 pages at a time) save each chunk when it is done.
Then finally open the chunks to combine them into one huge document.

If you really need millions of objects on a single page, then create a new page, draw 1,000,000 objects, save it, close it. Open the page again, draw another million objects, save it, close it, &c.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 10, 2015 1:17 pm 
Offline

Joined: Fri Sep 06, 2013 7:01 am
Posts: 27
Location: Cologne, Germany
this is exactly what I need

Thank you


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 99 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group