Create A Booklet with PDF – C#/VB.NET

Booklet, a small small book with several pages, is very convenient for carrying. We can find many booklets in our daily life, such as operating instruction, leaflet and so on. Also, we can create booklet by ourselves to record some useful words or interesting things. For example, an animation enthusiast can collect instructions and posters about great comics and create a booklet. In this post, I will show a method about how to create a booklet by using an existed PDF document with C#/VB.NET.

In my example, there is a PDF document which talks about Shelley. What I will do is to create it as a booklet. The two pages contents will be put in one page with two columns in this new booklet.

Original Document

Now, let’s go to create. At the beginning, we need to add references in project. The first one is Spire.PDF dll file because I use it to realize this function. The second one is system.drawing for page size setting, including width and height.

Then, the following shows details in step.

  1. Create a new PDF document.
  2. Create booklet. We need to send four parameters in doc.CreateBooklet() method, file name, width, height and a bool value to set if the contents in one page will be separate with two column. For file name, I declare a string type. Its value is the PDF document which I want to create as booklet. For width and height, their values are set based on A4 page size.
  3. Save and launch this booklet.

Main Coding:

C#

using System;

using Spire.Pdf;

namespace PDFBooklet

{

    class Booklet

    {

        static void Main(string[] args)

        {

            //Create PDF

            PdfDocument doc = new PdfDocument();

            //Create Booklet

            String srcPdf = @”D:\work\My Documents\Shelley.pdf”;

            float width = PdfPageSize.A4.Width * 2;

            float height = PdfPageSize.A4.Height;

            doc.CreateBooklet(srcPdf, width, height, true);

            //Save and Launch File

            doc.SaveToFile(“Booklet.pdf”);

            doc.Close();

            System.Diagnostics.Process.Start(“Booklet.pdf”);

        }

    }

}

VB.NET

Imports System

Imports Spire.Pdf

Namespace PDFBooklet

       Friend Class Booklet

              Shared Sub Main(ByVal args() As String)

                     ‘Create PDF

                     Dim doc As New PdfDocument()

                     ‘Create Booklet

                     Dim srcPdf As String = “D:\work\My Documents\Shelley.pdf”

                     Dim width As Single = PdfPageSize.A4.Width * 2

                     Dim height As Single = PdfPageSize.A4.Height

                     doc.CreateBooklet(srcPdf, width, height, True)

                     ‘Save and Launch File

                     doc.SaveToFile(“Booklet.pdf”)

                     doc.Close()

                     System.Diagnostics.Process.Start(“Booklet.pdf”)

End Sub

       End Class

End Namespace

Result Shown by Following:

______________________________________________________________________________

Click Here to Learn more about Spire.PDF

Click Here to Download Spire.PDF

Advertisements

Author: janewdaisy

.NET Program Beginner. Share methods about how to use C#/VB.NET to export data, operate Word, Excel, PDF and other useful skills.

1 thought on “Create A Booklet with PDF – C#/VB.NET”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s