PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Oct 27, 2015 10:20 am 
Offline

Joined: Mon Oct 19, 2015 8:41 am
Posts: 2
Hi, PDFSharp Team,

I am trying to resize an existing PDF file but the result is not centered, what am I doing wrong? I am using PDFsharp and a cropped PDF as input, please see below code:

Code:
Private Sub ResizePDF(sourcePDF As String, outPDF As String)
    Dim form As XPdfForm = XPdfForm.FromFile(sourcePDF)
    Dim doc2 As New PdfSharp.Pdf.PdfDocument()
    doc2.Options.CompressContentStreams = True
    doc2.Options.ColorMode = PdfSharp.Pdf.PdfColorMode.Rgb
    For pagenumber As Integer = 1 To (form.PageCount + 1) - 1
        Dim page As PdfSharp.Pdf.PdfPage = doc2.Pages.Add()
        form.PageNumber = pagenumber
        page.Width = form.PixelWidth + 15.36
        page.Height = form.PixelHeight + 40.32
        Dim graph As XGraphics = XGraphics.FromPdfPage(page)
        Dim rect As New XRect(0, 0, page.Width, page.Height)
        graph.DrawImage(form, rect)
    Next
    If IO.Directory.Exists(IO.Path.GetDirectoryName(outPDF)) = False Then IO.Directory.CreateDirectory(IO.Path.GetDirectoryName(outPDF))
    doc2.Save(outPDF)
End Sub


Please see below input and output file:

Input file: https://www.dropbox.com/s/po87x8c44r90p ... 1.pdf?dl=0
Ouput File: https://www.dropbox.com/s/pt5pcyfayri6o ... t.pdf?dl=0

I guess the problem here is I need to remove first the margins of cropped PDF but I don't know how to do that in PDFSharp, can someone point me into right direction? Thank you very much in advance.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 27, 2015 12:43 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
Already asked on Stack Overflow:
http://stackoverflow.com/q/33183686/1015447

This does work with many other input files, but it seems your input file needs some special treatment in PDFsharp.

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


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 28, 2015 6:27 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 951
Location: CCAA
Solution shown on Stack Overflow:
http://stackoverflow.com/a/33393447/1015447

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 29, 2015 1:55 pm 
Offline

Joined: Mon Oct 19, 2015 8:41 am
Posts: 2
TH-Soft wrote:
Solution shown on Stack Overflow:
http://stackoverflow.com/a/33393447/1015447


Thank you very much for the work around.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 19 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