PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jul 02, 2024 5:22 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Creates too large a file
PostPosted: Wed Jul 01, 2009 2:06 pm 
Offline

Joined: Wed Jul 01, 2009 1:53 pm
Posts: 5
I have successfully implemented a few web services using PDF Sharp. Unfortunately I am a bit stumped by the file size of the output - in my case I experimented with text only - and a 70 page report turns out to be 24.5MB without images.

Am I missing something, should I be rendering the document in another way? I looked through the examples but haven't found anything similar to my issue.

Thanks for any comments or help.


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 01, 2009 3:12 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
The release build creates smaller files.
But even the debug build shouldn't create files without images of that size.

No images?
Well, how many different fonts are you using?

Not long ago I played with a Word macro that enumerated all fonts on the computer ...

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Jul 01, 2009 3:49 pm 
Offline

Joined: Wed Jul 01, 2009 1:53 pm
Posts: 5
Thomas

Thanks for your quick reply - I use only one font - Verdana - we also have our own font which we plan to use in other portions, but it is not being used in these documents.

Before creating this application, I created a test app which produces only 7 pages - and it turns out to be 2.3MB.

I am using the 1.2.1269-g version.

There is no compress function that I should be using - I found none in the samples: pretty much this is the structure I use:

Set document variable
open document
add page
create text
add page
create text
etc
save document
close document

Thanks
Johan Kruger


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 02, 2009 8:25 am 
Offline
PDFsharp Guru
User avatar

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

If you want to find out what makes the file so big, you could
  • open it with PDFsharp Explorer and look what's in it
  • open it with Write/WordPad and look
  • zip the file and put it on a server and I'll take a look (post the URL here or send it via PM)

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 02, 2009 12:38 pm 
Offline

Joined: Wed Jul 01, 2009 1:53 pm
Posts: 5
Thanks Thomas

I think I know why the file is so big, and that will bring me to a question about formatting. I put a smaller file (9MB) on there, the comcept is the same. This one contains images though (but I don't think that the problem is the images).

I put the file on www.astrologysoftware.com/eros008jk.pdf

The problem I think is this - I build the paragraphs in a certain way because of alternate format proportions - I thought that doing it this way will give me more control over where I can put text, but it leads to me putting a whole lot of objects on pages.

My question thus is: Can I build this kind of formatting in another way without sacrificing the control over it? Things like italic/bold/images inside of paragraphs is something I'd like to control, and controlling which paragraphs belong together without splitting them over 2 pages etc, but it means that I am using DrawString to put each word down separately. And I think that is where the problem is?

If you have the time I'd appreciate your feedback.

Thank you again.

Johan Kruger


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 02, 2009 1:26 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Johan,

you are using a DEBUG build (if you open that PDF file with WordPad you'll see "% PDFsharp Version 1.2.1269.0 (verbose mode)").
A RELEASE build uses the non-verbose mode automatically - and filesize should fall to 25% through 50% or so (depending on the file).

Your file really contains a lot of objects.
MigraDoc is my area of expertise - and a 50 page document created with QBX 2008 and MigraDoc contains 563 objects in the PDF file (avg. of 11 objects per page).
Your document with 34 pages has 37974 objects ...

The file contains many empty objects.
And in verbose mode this looks like:
Code:
%--------------------------------------------------------------------------------------------------
37861 0 obj   % PdfSharp.Pdf.Advanced.PdfContent
<<
  /Length 0
>>
stream
endstream
endobj
%--------------------------------------------------------------------------------------------------

Maybe they come from drawing spaces ...

Here's the code that draws "is":
Code:
37862 0 obj   % PdfSharp.Pdf.Advanced.PdfContent
<<
  /Length 86
>>
stream
q
1 0 0 -1 0 792 cm -100 Tz
q
BT
/GS0 gs
/F0 -10 Tf
493.49 456.8561 Td (is) Tj
ET
Q
Q
endstream
endobj


You guessed it: drawing more text with identical font settings should reduce the file size.
But try a RELEASE build first - just to see how much smaller files will be.
Then stop drawing spaces - this should also save a few bytes.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jul 02, 2009 3:17 pm 
Offline

Joined: Wed Jul 01, 2009 1:53 pm
Posts: 5
Thomas

Yes, I was using a debug version, didn't even occur to me that that could have been an issue. And your other suggestions are right on, somehow I am going to have to find a way of creating blocks of writable text - anyway, thanks for your input - I will keep you up to date if I come across anything that might help someone else - but I did manage to save about 46% on the file size (24MB down to 13MB, 9MB down to 5MB etc) by just making it a release version.

Thanks

Johan Kruger


Top
 Profile  
Reply with quote  
PostPosted: Tue May 11, 2010 8:34 pm 
Offline

Joined: Tue May 11, 2010 8:22 pm
Posts: 2
Hi,

I am using migraDoc in the asp.net page. I did not find any option to build the website as a release version. I tried to publish the site and the pdf it generated still showed me the verbose mode (PDFsharp Version 1.31.1789.0 (verbose mode)).

From sample, pdfDocument can set document.Options.CompressContentStreams = true. Any thing that works for MigraDoc.DocumentObjectModel document?

Thanks in advance.

Yang


Top
 Profile  
Reply with quote  
PostPosted: Wed May 12, 2010 7:10 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!
fy04 wrote:
I did not find any option to build the website as a release version.

Create a Release build for MigraDoc and PDFsharp.

In the Visual Studio toolbar there's a dropdown listbox that allows to select between Release and Debug.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 12, 2010 5:57 pm 
Offline

Joined: Tue May 11, 2010 8:22 pm
Posts: 2
Thank you. It worked.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 70 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