[RESOLVED]Auto merge 2 PDF file to 1 PDF

Dear all,

i am using vb.net

i am facing problem to use the vb.net to merge two PDF to 1 file.

i do not have any third party software to do it.

i want to make it as auto merge when click a button.

    Private pTmpFilePath_Upload As String = Server.MapPath("..TMRAttachment_Upload")
    Private pTmpFilePath_Generate As String = Server.MapPath("..TMRAttachment_Generate")
    Private pTmpFilePath_Final As String = Server.MapPath("..TMRAttachment_Final")

location A + location B, then save it at location C
both 3 files are same file name.

Looking forward your help.

Thank you

HI,

i think you require adobe acrobar professional dll for this, adobe acobat professional have this feature.

or try this

http://www.dotnetspider.com/resources/36210-Merge-PDF-File-using-itextsharp-library.aspx

Hi,

ccs2090

i am facing problem to use the vb.net to merge two PDF to 1 file.

iTextSharp can be used to Merge two pdf files.

You can download it here -http://sourceforge.net/projects/itextsharp/files/

It’s a dll download it ,add reference and use it.

using iTextSharp.text;
using iTextSharp.text.pdf;

Here is working sample though it is in C# you can refer and use it. It takes two PDF files as Input and merges them to a third PDF File.

namespace MergePdf
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] files = @"D:PDF1.pdf,D:PDF2.pdf".Split(',');
            MergeFiles(@"D:PDF.pdf", files);
        }

        public static void MergeFiles(string destinationFile, string[] sourceFiles)
        {
            if (System.IO.File.Exists(destinationFile))
                System.IO.File.Delete(destinationFile);

            string[] sSrcFile;
            sSrcFile = new string[2];

            string[] arr = new string[2];
            for (int i = 0; i <= sourceFiles.Length - 1; i++)
            {
                if (sourceFiles[i] != null)
                {
                    if (sourceFiles[i].Trim() != "")
                        arr[i] = sourceFiles[i].ToString();
                }
            }

            if (arr != null)
            {
                sSrcFile = new string[2];

                for (int ic = 0; ic <= arr.Length - 1; ic++)
                {
                    sSrcFile[ic] = arr[ic].ToString();
                }
            }
            try
            {
                int f = 0;

                PdfReader reader = new PdfReader(sSrcFile[f]);
                int n = reader.NumberOfPages;
                Console.Write("There are " + n + " pages in the original file.");
                Document document = new Document(PageSize.A4);

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));

                document.Open();
                PdfContentByte cb = writer.DirectContent;
                PdfImportedPage page;

                int rotation;
                while (f < sSrcFile.Length)
                {
                    int i = 0;
                    while (i < n)
                    {
                        i++;

                        document.SetPageSize(PageSize.A4);
                        document.NewPage();
                        page = writer.GetImportedPage(reader, i);

                        rotation = reader.GetPageRotation(i);
                        if (rotation == 90 || rotation == 270)
                        {
                            cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
                        }
                        else
                        {
                            cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
                        }
                        Console.Write("n Processed page " + i);
                    }

                    f++;
                    if (f < sSrcFile.Length)
                    {
                        reader = new PdfReader(sSrcFile[f]);
                        n = reader.NumberOfPages;
                        Console.Write("There are " + n + " pages in the original file.");
                    }
                }
                Console.Write("Success");
                document.Close();
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
        }
    }
}

For more refernce . Here is a link that might be useful to you. It’s in VB -http://www.vbforums.com/showthread.php?475920-Merge-Pdf-Files-and-Add-Bookmarks-to-It-(Using-iTextSharp)

To know more about iTextSharp and the API -http://itextpdf.com/product

Best Regards!

Note:
Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
Please make sure that you completely understand the risk before retrieving any suggestions from the above link.

 

 

Use itextsharp. It is a third party dll but is open source…

http://www.markkoops.com/merge-pdf-files-with-itextsharp/

sorry, i reply late. i able to do it by itextsharp.

thanks a lot.

Just want to add something about iTextSharp that seems to be ignored… from http://itextpdf.com/purchase

Buying a commercial license is mandatory as soon as you begin commercial activities including distribution of iText software inside your product or deploying it on a network without
disclosing the source code of your own applications under the AGPL license
. These activities include but are not limited to offering paid services to customers as a SaaS, serving PDFs on the fly in the cloud or in a web application,
or shipping iText with a closed source product.

An alternative to iTextSharp is PDFSharp (http://www.pdfsharp.net/wiki/ConcatenateDocuments-sample.ashx)

Neodynamic

Just want to add something about iTextSharp that seems to be ignored… from http://itextpdf.com/purchase

That ony applies to iTextSharp 5. You can use 4.1.6 freely without these restrictions as its licence is LGPL/MPL: http://www.nuget.org/packages/iTextSharp-LGPL

Leave a Reply