PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Resizing existing pdfpage not top centered https://forum.pdfsharp.net/viewtopic.php?f=2&t=3218 |
Page 1 of 1 |
Author: | renzlo [ Tue Oct 27, 2015 10:20 am ] |
Post subject: | Resizing existing pdfpage not top centered |
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. |
Author: | TH-Soft [ Tue Oct 27, 2015 12:43 pm ] |
Post subject: | Re: Resizing existing pdfpage not top centered |
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. |
Author: | TH-Soft [ Wed Oct 28, 2015 6:27 pm ] |
Post subject: | Re: Resizing existing pdfpage not top centered |
Solution shown on Stack Overflow: http://stackoverflow.com/a/33393447/1015447 |
Author: | renzlo [ Thu Oct 29, 2015 1:55 pm ] |
Post subject: | Re: Resizing existing pdfpage not top centered |
TH-Soft wrote: Solution shown on Stack Overflow: http://stackoverflow.com/a/33393447/1015447 Thank you very much for the work around. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |