C # merge PDF files in multiple formats,

Source: Internet
Author: User

C # merge PDF files in multiple formats,

Document merging is an efficient document processing method. If there is one way to combine multiple different types of documents into one document format, it will be very convenient for us to manage document storage. Therefore, this article describes how to use the Free Spire. Office for. NET component to merge various types of documents into PDF files. The document formats that can be merged in this method can be doc, docx, xls, xlsx, and pdf. The following is a detailed description.

Usage: After installing Free Spire. Office for .net, refer to the spire.doc. dll, spire.xls. dll, and spirew.dll files, as shown in:

Add the following using command to the namespace:

using Spire.Doc;using Spire.Xls;using Spire.Pdf;using System.IO;

Before merging documents:

Main Code:

// Declare the audit Document Object array legal document [] Legal ents = new legal document [4]; using (MemoryStream ms1 = new MemoryStream ()) {// load doc Document doc = new Document (@ "C: \ Users \ Administrator \ Desktop \ sample.doc", Spire. doc. fileFormat. doc); // convert the PDF file and save the doc as a stream. saveToStream (ms1, Spire. doc. fileFormat. PDF); // load the PDF stream file as the first element in the Document Object array, documents [0] = new document (ms1);} using (MemoryStream ms2 = new MemoryStream ()) {// load docx Document docx = new Document (@ "C: \ Users \ Administrator \ Desktop \ test.docx", Spire. doc. fileFormat. docx2010); // convert the PDF file and save docx as a stream. saveToStream (ms2, Spire. doc. fileFormat. PDF); // load the PDF stream file as the second element of the Document Object array, documents [1] = new document (ms2);} using (MemoryStream ms3 = new MemoryStream ()) {// load the xlsx document Workbook workbook = new Workbook (); workbook. loadFromFile (@ "C: \ Users \ Administrator \ Desktop \ Sample.xlsx", ExcelVersion. version97to2003); // converts a PDF file and saves the workbook as a stream. saveToStream (ms3, Spire. xls. fileFormat. PDF); // load the PDF stream file as the third element of the Document Object array, documents [2] = new document (ms3);} // load the pdf document, as the fourth element of the Document Object array, documents [3] = new documents (@ "C: \ Users \ Administrator \ Desktop \ sample.pdf "); // merge the first three documents into the fourth document and save it as a new PDF document for (int I = 2; I>-1; I --) {documents [3]. appendPage (documents [I]);} documents [3]. saveToFile ("resultsuccess ");

After the code is complete, debug and run the project to generate a file.

Merge effect display:

All of the above is to merge different formats of files as PDF files, if you want to merge multiple single format of PDF documents into a file, see this article: http://www.cnblogs.com/Yesi/p/5604166.html.

If you like this article, you are welcome to repost it. (For more information, see the source)

Thank you for browsing!

Related Article

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.