PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 01, 2024 8:19 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: Wed Oct 16, 2013 3:03 pm 
Offline

Joined: Wed Oct 16, 2013 11:48 am
Posts: 2
I got some Problems with Saving a Canvas to a A3 PDF.
I'm currently in my internship semester so it's the first time I’m working with PDFsharp so i'm sorry if there may a lot of easier ways to do this:)
First Problem i got was that if I use PdfSharp.PageSize.A3 the Resolution was to low it was fuzzy. So i Added a new A3 Resolutions with 300dpi, called A3300.

I show all Canvas in an TabControle Window. From This Window i start creating my pdf.
Now it works fine if i create Just the first page(Canvas). But i need up to 10 pages. Then always the first page is ok and the others are empty. About this i found out if i Open the Canvas in an extra window before i create the pdf with ShowDialog() it works for all.. Im really confused.

Second Problem i'm running out of memory because the XGraphics File got each page ~700MB later as PDF 0.7MB. I tried it with gfx.Dispose(); but it didn't work.

So what is the problem with the empty pages if i don't open an extra window and is there a way to delete the gfx file from the memory?

//PDF creating
Code:
 try
            {     
                    s_document = new PdfDocument();
                    s_document.Info.Title = "PDFKlemmen";
                    s_document.Info.Author = Environment.UserName + " FESTO AG & Co. KG ";
                    s_document.Info.Subject = "Belegungsplan IO";

                for (int i = 0; i < 2; i++) Can create 2 without memory exception
                {
                    cCanvastest ct = new cCanvastest(Can[i]); //Open the Canvas ina window
                    ct.ShowDialog();
                    PdfSharp.Pdf.PdfPage page = s_document.AddPage();

                    switch ((int)dpi)
                    {
                        case 72: page.Size = PdfSharp.PageSize.A372; break;
                        case 96: page.Size = PdfSharp.PageSize.A396; break;
                        case 300: page.Size = PdfSharp.PageSize.A3300; break;
                        default: page.Size = PdfSharp.PageSize.A3300; dpi = 300d; break;
                    }

                    RenderTargetBitmap bitmap = new RenderTargetBitmap((int)(1114 / 72 * dpi), (int)(1584 / 72 * dpi), dpi, dpi, PixelFormats.Pbgra32);
                    bitmap.Render(Can[i]);
                    BitmapEncoder encoder = new BmpBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create(bitmap));


                    BitmapImage bmp = new BitmapImage() { CacheOption = BitmapCacheOption.OnLoad };
                    System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                    encoder.Save(outStream);
                    outStream.Seek(0, System.IO.SeekOrigin.Begin);
                    bmp.BeginInit();
                    bmp.StreamSource = outStream;
                    bmp.EndInit();

                    XImage image = XImage.FromBitmapSource(bmp);
                    XGraphics gfx = XGraphics.FromPdfPage(page);

                    gfx.DrawImage(image, 0, 0, image.PixelWidth, image.PixelHeight);

                    gfx.Dispose();
                    image.Dispose();
                    outStream.Close();
                    ct.Close();
                }
               
                s_document.Save(sPfad);
             }



I hope some one can help me:)


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2013 4:51 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
Stefan Erler wrote:
First Problem i got was that if I use PdfSharp.PageSize.A3 the Resolution was to low it was fuzzy. So i Added a new A3 Resolutions with 300dpi, called A3300.
PDF files are vector files and have no DPI at all. You can call DrawImage to draw any image at any size (without adding dummy page sizes to PDFsharp).

I can't help with the canvas problem.

With respect to memory usage: There are two builds you can try: GDI+ and WPF.
You can do it in two phases: create 10 PDF files with one page each in the first phase, then concatenate them to one big PDF in the second phase. This may reduce the memory consumption.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 17, 2013 8:03 am 
Offline

Joined: Wed Oct 16, 2013 11:48 am
Posts: 2
Thank you for you Replay Thomas Hoevel
It helps me a lot.
Quote:
PDF files are vector files and have no DPI at all. You can call DrawImage to draw any image at any size (without adding dummy page sizes to PDFsharp).
I didn't know that, so it was just a DrawImage scale problem at all.

Quote:
create 10 PDF files with one page each in the first phase, then concatenate them to one big PDF
I used that way now, I didn’t tried that before because i thought if i will import them they use the same space as before...

So Just the Canvas problem Left.


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 48 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