Posts Tagged ‘apache’

Merging pdf using Apache PDFBox

November 5th, 2013 No comments

I was working on a problem in which we wanted to merge multiple pdf. We were using itext for merging pdf but wanted to try out open source alternative. The logical choice was ApachePDF Box.
It is not that IText does not work or the license fees is high. The organisation was trying to save few extra bucks although I firmly believe that a programmer should be paid for his hard work.

Below is the code sample for pdf merging with apache pdfbox

public class PDFDocumentMergerService {

private static final Log LOG = LogFactory

public void concatPDFWithPDFBOX(
final List<InputStream> streamOfPDFFiles,
final OutputStream outputStream) {

try {

PDFMergerUtility mergePdf = new PDFMergerUtility();
for (InputStream inputDoc : streamOfPDFFiles) {


catch (IOException ioe) {
throw new DocumentMergeException("Pdf merge failed.", ioe);
catch (COSVisitorException ex) {
throw new DocumentMergeException("Pdf merge failed.", ex);

public byte[] mergeDocuments(final List<byte[]> documentContents) {

List<InputStream> inputStreams = new ArrayList<InputStream>(

for (byte[] content : documentContents) {
inputStreams.add(new ByteArrayInputStream(content));

ByteArrayOutputStream mergedStream = new ByteArrayOutputStream();

long startTime2 = System.currentTimeMillis();

this.concatPDFWithPDFBOX(inputStreams, mergedStream);

long endTime2 = System.currentTimeMillis();" Time to create PDF with PDF Box "
+ (endTime2 - startTime2));

byte[] outputData = mergedStream.toByteArray();

return outputData;


The performance was excellent and comparable to itext.

Categories: Uncategorized Tags:

Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

February 7th, 2011 No comments

If you are seeing this error, enable in httpd.conf

LoadModule headers_module modules/

Categories: Uncategorized Tags:

Adding Access-Control-Allow-Origin to server for Cross domain scripting

February 4th, 2011 1 comment

Cross domain scripting would be such a big issue especially in year 2011, I never imagined. What I had envisioned to be a small problem turned out to be much bigger and complicated than I thought.

Let us go over the problem statement first

I have application 1 making a json request to

While it works in IE(I was working with IE6) , it will fail in Firefox (I was using FF 3.6)

From Mozilla docs

Cross-site HTTP requests are HTTP requests for resources from a different domain than the domain of the resource making the request.  For instance, a resource loaded from Domain A (http://domaina.example) such as an HTML web page, makes a request for a resource on Domain B (, such as an image, using the img element (  This occurs very commonly on the web today — pages load a number of resources in a cross-site manner, including CSS stylesheets, images and scripts, and other resources.

Or another example

http:/  making call to http:/

will also be not allowed in FF because even on same server and different port number , it considers it cross domain scripting. Read more…

Categories: Uncategorized Tags:

Configuring Tomcat with Apache

February 2nd, 2011 4 comments

In this post we will describe how to set up Apache web server with Tomcat.

We have used  Tomcat 6.0.29 and Apache 2.2.17 but the settings describe here will work for Tomcat 7 as well.

1. We will need to install mod_jk on apache

Mod_jk can be downloaded  from this location

2. Copy to <Install Location>\Apache Software Foundation\Apache2.2\modules

3. Create a in conf folder of apache

A sample


# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.

# You should configure your environment slash… ps=\ on NT and / on UNIX
# and maybe something different elsewhere.

# The workers that your plugins should create and work with

#—— DEFAULT ajp13 WORKER DEFINITION ——————————
# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.

#—— CLASSPATH DEFINITION —————————————–
# Additional class path components.

# The JVM that we are about to use
# Unix – Sun VM or blackdown

# Setting the place for the stdout and stderr of tomcat

4. Use Tomcat auto configure.

To be added at the end of your httpd.conf

Include $TOMCAT_HOME/conf/jk/mod_jk.conf-auto

5. Re start tomcat and re start Apche.

You will find two folders auto and jk created under TOMCAT_HOME/conf.

You will also find this value inserted in conf.xml

<Listener className=”org.apache.jk.config.ApacheConfig” modJk=”<Your apache directory>/Apache2.2/modules/” />

Common Issues: Read more…

Categories: Uncategorized Tags:

Apache Pivot Presentation at NEJUG

May 20th, 2010 No comments

NEJUG on Thu, Jun 10, will feature Greg Brown presenting on Apache Pivot and we will be at Sun Microsystems Burlington , MA.

Presentation Overview:

Apache Pivot ( is a platform for building rich Internet applications (RIAs) in Java. It combines the enhanced productivity and usability features of a modern RIA toolkit with the robustness of the industry-standard Java platform. Pivot includes a number of features that significantly simplify development of modern GUI applications, including an XML markup language for declaring the structure of a user interface, data binding, animated effects and transitions, and Web services integration.

In this session, Pivot founders Greg Brown and Todd Volkert provide an overview of the Pivot platform and walk through the implementation of a simple but practical application that highlights key platform features and development best practices.

About the presenter:

Greg Brown is a senior software architect with 15 years of experience developing applications in both a services and R&D capacity. He is the founder and PMC Chair of Apache Pivot, an open source platform for building rich Internet applications in Java. He holds a bachelor?s degree in Computer Systems Engineering from the University of Massachusetts Amherst.

Categories: Uncategorized Tags: