PDFUtils

Utility methods to convert PDF files. For example, to stamp image or text. 

Methods

merge

Description:

MethodReturn valuesDescription

merge(List<InputStream> inputs, OutputStream output)

void

Merge several PDFs into a new one.

inputs: List of inputs stream for merge.

output: Output stream of the file.

Example:

package com.openkm;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;
import com.openkm.util.PDFUtils;
import com.openkm.util.PathUtils;
import com.openkm.util.FileUtils;

public class Test {
	public static void main(String[] args) {
		FileOutputStream fos = null;
		FileInputStream fis = null;
		File tmp = null;
		try {
			List<InputStream> inputs = new ArrayList<InputStream>();	
			tmp = FileUtils.createTempFile("pdf");
			fos = new FileOutputStream(tmp);

			inputs.add(OKMDocument.getInstance().getContent(null, "/home/openkm/test1.pdf", false));
			inputs.add(OKMDocument.getInstance().getContent(null, "/home/openkm/test2.pdf", false));

			// Merge document
			PDFUtils.merge(inputs, fos);

			// Create document in repository
			String fldPath = PathUtils.getParent("/home/openkm/test1.pdf"); // all documents are in same path
			String docPath = fldPath + "/docMerge";
			fis = new FileInputStream(tmp);
			OKMDocument.getInstance().createSimple(null, docPath, fis);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			IOUtils.closeQuietly(fis);
			IOUtils.closeQuietly(fos);
			FileUtils.deleteQuietly(tmp);
		}
	}
}