Aspose Demos > Java Components > Aspose.Pdf.Kit for Java > Java > Concatenate PDF

Concatenate PDF - Aspose.Pdf.Kit

This demo Concatenates two input PDF files into a single output file. Using Concatenate method in PdfFileEditor class of Aspose.Pdf.Kit component, you can merge/concatenate multiple Pdf documents into a single Pdf file.

Fore more information, please visitConcatenate PDF Documents.


Click Execute Demo to see how demo concatenatespdf document 1 andpdf document 2 enabling user to download results of concatenation.









JAVA

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

package com.aspose.pdf.kit.demos.jsf;

import java.io.Serializable;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.aspose.pdf.kit.*;

public class Concatenate extends BaseDemo
{
    // Default Constructor
    public Concatenate() {
    }

    /**
     * Execute request
     *
     * @return success
     */

    public Boolean execute(HttpServletRequest request, HttpServletResponse response)
    {
        try
        {
            String path = "/resources/";

            //read the input file
            String inFile1 = path + "Aspose.Pdf.Kit.pdf";
            String inFile2 = path + "Aspose.Pdf.pdf";

            InputStream inStream1 = getFile(request, inFile1);
            if (null==inStream1)
            {
                System.out.println("concatenate: NULL stream for " + inFile1);
                return false;
            }

            InputStream inStream2 = getFile(request, inFile2);
            if (null==inStream2)
            {
                System.out.println("concatenate: NULL stream for " + inFile2);
                return false;
            }

            // Concatenate two files
            PdfFileEditor editor = new PdfFileEditor();
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            editor.concatenate(inStream1, inStream2, output);

            setResponse(FILE_NAME, output);
            return true;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }

        return false;
    }
}

XHTML

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:ice="http://www.icesoft.com/icefaces/component"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jstl/core"
      >

<ui:composition template="/WEB-INF/includes/templates/page-template.xhtml">
                        
    <ui:define name="pageTitle">
        Concatenate PDF - Aspose.Pdf Demos
    </ui:define>

    <ui:define name="page-content">
        <ui:decorate template="/WEB-INF/includes/templates/tabbed_container.xhtml">
            <ui:define name="example">

    

<table width="90%" align="center" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td width="19"><img src="../../../../Common/images/heading_lft.jpg" alt="" width="19" height="41" /></td>
    <td width="100%" class="demos-heading-bg"><h2 class="demos-heading-bg"> &nbsp;Concatenate PDF - Aspose.Pdf.Kit</h2></td>
    <td width="19"><img src="../../../../Common/images/heading_rt.jpg" alt="" width="19" height="41" /></td>
  </tr>
<tr>&nbsp;</tr>
</table>


<p class="componentDescriptionTxt">
 This demo <b> Concatenates </b>  two input PDF files into a single output file. Using <b> Concatenate </b> method in <a href="http://www.aspose.com/documentation/java-components/aspose.pdf.kit-for-java/com/aspose/pdf/kit/pdffileeditor.html"> PdfFileEditor</a> class of Aspose.Pdf.Kit component, you can merge/concatenate multiple Pdf documents into a single Pdf file.

<br/><br/>
Fore more information, please visit <a href="http://www.aspose.com/documentation/java-components/aspose.pdf.kit-for-java/concatenate-pdf-documents.html">Concatenate PDF Documents. </a>

<br/><br/><br/>Click <b> Execute Demo </b> to see how demo concatenates <a href="../resources/Aspose.Pdf.Kit.pdf">pdf document 1</a> and
        <a href="../resources/Aspose.Pdf.pdf">pdf document 2</a> enabling user to download results
        of concatenation.
        </p>

        

    <h:commandButton id="generate" 
                action="#{mycontext.generate}"
                actionListener="#{mycontext.action}"
                value="Execute Demo"> 
                <f:attribute name="demo" value="concatenate" />
            </h:commandButton>

            <ice:outputResource id="pdfResource"
                mimeType="application/pdf"
                value="Execute Demo"
                resource="#{mycontext.generatedfile}"
                fileName="#{mycontext.filename}"
                shared="false" />

            <br/><br/><br/><br/><br/><br/><br/><br/></ui:define>
        
</ui:decorate>
    </ui:define>
</ui:composition>
</html>