PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 9:29 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed May 11, 2016 6:52 am 
Offline

Joined: Wed May 11, 2016 6:19 am
Posts: 4
Hi,

I am using PdfSharp to create a new Pdf file from another pdf file. I can successfully create the new one. But we have a requirement to add a margin in the newly created pdf file (say 10 pts on all sides). I have tried setting the TrimMargin, but this is pushing the page contents to various corners of the page, instead of scaling. The expected behavior is to scale the page contents according to the margin.

Later, instead of importing, I created the new page using XGraphics.DrawImage from the XForm object of the source pdf file and with a scaled down XRect with margins set. However, some pages gets distorted and it never draws the image inside the rectangle that I specify.

So can someone please suggest the recommended way of scaling the pdf page either by importing or DrawImage function?

Thanks in advance
Sai Theodore


Top
 Profile  
Reply with quote  
PostPosted: Wed May 11, 2016 7:38 am 
Offline
PDFsharp Guru
User avatar

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

I would use DrawImage. I would scale down the PDF page maintaining the aspect ratio.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 12, 2016 8:35 am 
Offline

Joined: Wed May 11, 2016 6:19 am
Posts: 4
Thanks a lot for the quick response.

I am using the exact same method as you have suggested. Though most of the pages comes prefect, for some reason certain pages get distorted and never draws it inside the rectangle that I mention. One thing I noticed is that it happens to pages which are rotated.

Any idea why would this happen?


Top
 Profile  
Reply with quote  
PostPosted: Thu May 12, 2016 8:46 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
saitheodore wrote:
One thing I noticed is that it happens to pages which are rotated.
If this happens to pages that are rotated by 180° then this fix may help you:
viewtopic.php?p=9868#p9868

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 12, 2016 9:01 am 
Offline

Joined: Wed May 11, 2016 6:19 am
Posts: 4
Thanks a lot Thomas. Will try this.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 13, 2016 6:25 pm 
Offline

Joined: Fri May 13, 2016 5:44 pm
Posts: 6
When scaling the image and page down per the suggestion, does it also change the file size of the PDF? Say for example a PDF is sized at 2 MB. If when using PdfSharp, get the page as an image, scale it down to a smaller width and height, will it change the file size as well? Ideally yes, it would, but when researching online it seems using PdfSharp, it will not reduce the file size.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 13, 2016 8:13 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
jboss26 wrote:
Ideally yes, it would
No, ideally the size will not change.
PDF is a vector format. You draw the page smaller, but the contents that are drawn do not change in any way.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Sun May 15, 2016 12:44 am 
Offline

Joined: Fri May 13, 2016 5:44 pm
Posts: 6
Sorry, I meant ideally in my situation. Essentially, we have a set of network folders where automated PDFs are created from a machine with measurement outputs, and these files tend to range from 1MB to 5MB. That in itself is not a problem, but when it exports one or two files every 1 hour, disk space gets eaten up relatively quickly. I am trying to find a way to program a simple app which will look in a specified directory, and scale the PDFs down, most importantly the file size.

If I understand correctly, PDFSharp does not support vector manipulation to the point of altering the original image's size, therefore reducing the file size when saved? Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Mon May 16, 2016 6:42 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 916
Location: CCAA
jboss26 wrote:
If I understand correctly, PDFSharp does not support vector manipulation to the point of altering the original image's size, therefore reducing the file size when saved?
Vector information is "draw a line here, draw a line there". You do not save anything if you draw the image on a smaller area as all items are still there. It is possible to add a filter that removes "small" insignificant items, but I never heard of such a tool.

There are tools that shrink raster images included in PDF files. PDFsharp does not do this.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

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