How to merge two PDF documents

Source: Internet
Author: User

Example

 

I have found a solution and have no time to upload it to share with you,

Itextsharp is used.

 

/// <Summary>
/// Merge PDF files
/// </Summary>
/// <Param name = "lstfiles"> list of files to be merged </param>
/// <Returns> </returns>
Private bool mergepdf (list <string> lstfiles)
{
Bool breturn = false;
Try
{
Int F = 1;
Pdfreader reader = new pdfreader (lstfiles [f]);
Int n = reader. numberofpages;
Document document = new document (reader. getpagesizewithrotation (1 ));
Using writer = Using writer. getinstance (document, new filestream (lstfiles [0], filemode. Create ));
Document. open ();
Required contentbyte cb = writer. directcontent;
Pdfimportedpage;
Int rotation;
While (F <lstfiles. Count)
{
Int I = 0;
While (I <n)
{
I ++;
Document. setpagesize (reader. getpagesizewithrotation (I ));
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 );
}
}
F ++;
If (F <lstfiles. Count)
{
Reader = new pdfreader (lstfiles [f]);
N = reader. numberofpages;
}
}
Document. Close ();
Breturn = true;
}
Catch
{
Breturn = false;
}
Return breturn;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.