Jump to content
Changes to the Jaspersoft community edition download ×

2004 IR Help

Recommended Posts

By: Cheong Weng Way - wwcheong

Merge PDF

2005-04-25 03:37

Hi,

 

I'm new to JasperReport. I want to know can jasperreport merge PDF files?

For example, I want to merge pdf files A and B to be C.

A.pdf + B.pdf = C.pdf

 

Thank you in advance.

 

 

 

 

By: CleverFool - cleverfool

RE: Merge PDF

2005-04-25 05:33

No. JasperReports is reporting tool, not PDF editing tool:)

 

 

 

 

By: C-Box - c-box

RE: Merge PDF

2005-04-25 08:08

I guess the question should more be: How to combine two reports to get one PDF outPut isn't it?

So try to surround your two reports with a masterreport that has tow dummygroups each contains a subreport and so you get one PrintObject (PDF) with both reports within.

 

hth

C-Box

 

 

 

 

By: Teodor Danciu - teodord

RE: Merge PDF

2005-04-25 08:17

 

Hi,

 

Also note that the exporters work in batch mode and

you could export several JasperPrint objects into the same

PDF file.

Check the "batchexport" sample provided.

 

I hope this helps.

Teodor

 

 

 

 

 

By: Cheong Weng Way - wwcheong

RE: Merge PDF

2005-04-25 23:21

According to CleverFool I cannot import (input) PDF file to JasperReports for merging, can i?

 

So there's no way JasperReports to support PDF merging, eventhough with subreport?

 

Thank you for all replies. I appreciate all.

I'm really begining to blend into JasperReports usage now.

 

 

 

 

 

By: C-Box - c-box

RE: Merge PDF

2005-04-26 01:42

You must decide between two things:

 

A) Do you want to merge an EXISTING PDF (must not be produced through JasperReports) with a PDF that JasperReports returns....

 

... if so then this is not a feature of a ReportingSoftware. That is your part!!!!!

 

B) Do you want to merge two PDF that are produced through JasperReports... then this would be possible either with SubReportDesign or with the BatchExporter Teodor describes a Post earlier.

 

now clear?

 

hth

C-Box

 

 

 

 

By: Cheong Weng Way - wwcheong

RE: Merge PDF

2005-04-26 02:46

Clear now. very clear.

Thank you C-Box and Teodor.

 

 

 

 

By: Jerish - jerish

RE: Merge PDF

2005-04-26 04:20

ypu can....please see the method below...

 

/**

* Performs PDF File Merging

* @param fileList

* @param path

*

*

*/

private File doPDFFileMerging(ArrayList fileList, String path) {

File outFile = null;

try {

int pageOffset = 0;

int f = 0;

ArrayList master = new ArrayList();

String args[] = new String[fileList.size()];

for (int i = 0; i < fileList.size(); i++) {

 

args = fileList.get(i).toString();

}

outFile = File.createTempFile("inv", null, new File(path));

Document document = null;

PdfCopy writer = null;

while (f < args.length) {

 

String fullFilePath = path + args[f];

File file = new File(fullFilePath);

if (file != null && file.exists()) {

 

// we create a reader for a certain document

PdfReader reader = new PdfReader(fullFilePath);

reader.consolidateNamedDestinations();

 

// we retrieve the total number of pages

int n = reader.getNumberOfPages();

pageOffset += n;

 

if (f == 0) {

// step 1: creation of a document-object

document =

new Document(reader.getPageSizeWithRotation(1));

// step 2: we create a writer that listens to the document

writer =

new PdfCopy(

document,

new FileOutputStream(outFile));

 

// step 3: we open the document

document.open();

}

// step 4: we add content

PdfImportedPage page;

for (int i = 0; i < n;) {

++i;

page = writer.getImportedPage(reader, i);

writer.addPage(page);

//writer.getPageEvent()

}

PRAcroForm form = reader.getAcroForm();

if (form != null)

writer.copyAcroForm(reader);

}

f++;

}

if (master != null && master.size() > 0)

writer.setOutlines(master);

// step 5: we close the document

if (document != null)

document.close();

// delete all temp file

for (int i = 0; i < fileList.size(); i++) {

new File(path + fileList.get(i).toString()).delete();

}

 

} catch (Exception e) {

log.error("Failed merging pdf files", e);

 

} finally {

return outFile;

}

}

 

 

pass all the pdf file names to fileList variable of the method.

 

Pls let me know if u need more clarifications.

Link to comment
Share on other sites

  • 4 years later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...