[VB.NET/C#] Resize PDF to specific page dimensions

Example requests & Code samples for GdPicture Toolkits.
Post Reply
exarte
Posts: 1
Joined: Wed Feb 01, 2012 10:06 am

[VB.NET/C#] Resize PDF to specific page dimensions

Post by exarte » Wed Feb 01, 2012 10:18 am

Hello,

I have a pdf file where every page is 899,6 mm x 1238,2 mm big. This huge size is problematic for other components of my program, so I would like to resize it to standard 297mm x 210 mm (a standard A4).

Is there an "easy" way to do this. The only way I've found so far, is converting every page to an image with the method "RenderPdfPageAsImage", then creating an empty pdf with pages of the correct size, and drawing all the created images on the new PDF. But this increases the size of the pdf heavily. If i lower the dpi of the created images, then the pdf at the end it smaller, but I lose way to much quality.

Thanks for the help,
Kind regards

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Resize PDF

Post by Loïc » Mon Feb 06, 2012 10:41 pm

Hello,

Unfortunately this feature is not yet supported. A workaround is to use the rasterization, but it is not really suitable for non image based PDF documents.

We should deliver such feature within 4 months.

Kind regards,

Loïc

bentigano
Posts: 5
Joined: Tue Aug 14, 2012 2:55 pm
Location: Boston, MA

Re: Resize PDF

Post by bentigano » Tue Aug 14, 2012 3:00 pm

Has there been any progress on this? We are using v9, and I'm trying to accomplish the same thing.

Basically, we have a legal document that we'd like to convert to letter size (8.5" x 11"), with a .5" margin. We are able to do this with PdfTron, but are converting everything over to GdPicture.NET.

Any advice would be greatly appreciated. Thanks!

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Resize PDF

Post by Loïc » Wed Aug 15, 2012 2:28 pm

Hello,

This can now be easily be done with 9.1 and higher:

Code: Select all

        Const PAGE_WIDTH As Integer = 210
        Const PAGE_HEIGHT As Integer = 297

        Using gdPicturePDF As New GdPicturePDF
            gdPicturePDF.LoadFromFile("c:\input.pdf", False)

            gdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
            Dim pageCount As Integer = gdPicturePDF.GetPageCount
            For i As Integer = 1 To pageCount
                gdPicturePDF.SelectPage(i)
                gdPicturePDF.NewPage(PAGE_WIDTH, PAGE_HEIGHT)
                gdPicturePDF.SelectPage(pageCount + 1)
                gdPicturePDF.DrawPage(gdPicturePDF, i, 0, 0, PAGE_WIDTH, PAGE_HEIGHT)
                gdPicturePDF.DeletePage(i)
                gdPicturePDF.MovePage(pageCount, i)
            Next

            gdPicturePDF.SaveToFile("c:\output.pdf", True)
        End Using
Let me know if you need further information.

Kind regards,

Loïc

bentigano
Posts: 5
Joined: Tue Aug 14, 2012 2:55 pm
Location: Boston, MA

Re: Resize PDF

Post by bentigano » Thu Oct 11, 2012 8:37 pm

Thanks so much for your help, Loic!

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Resize PDF

Post by Loïc » Fri Oct 12, 2012 11:41 am

You're welcome :)

By the way, there is now and even more easier way to do it:

using VB.NET

Code: Select all

Const PAGE_WIDTH As Integer = 210
Const PAGE_HEIGHT As Integer = 297

Using gdPicturePDF As New GdPicturePDF
   gdPicturePDF.LoadFromFile("c:\input.pdf", False)

   gdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
   Dim pageCount As Integer = gdPicturePDF.GetPageCount
   For i As Integer = 1 To pageCount
      gdPicturePDF.SelectPage(i)
      gdPicturePDF.ResizePage(PAGE_WIDTH, PAGE_HEIGHT)
   Next

   gdPicturePDF.SaveToFile("c:\output.pdf", True)
End Using
or C#

Code: Select all

const int PAGE_WIDTH = 210;
const int PAGE_HEIGHT = 297;

using (GdPicturePDF gdPicturePDF = new GdPicturePDF())
{
	gdPicturePDF.LoadFromFile("c:\\input.pdf", false);

	gdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
	int pageCount = gdPicturePDF.GetPageCount;
	for (int i = 1; i <= pageCount; i++) {
		gdPicturePDF.SelectPage(i);
		gdPicturePDF.ResizePage(PAGE_WIDTH, PAGE_HEIGHT);
	}

	gdPicturePDF.SaveToFile("c:\\output.pdf", true);
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest