Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

PDFileEditor.concatenate() produces zero byte output PDF.

$
0
0

I am trying the sample code to merge PDFs using PDFFileEditor.concatenate() method. Below is the sample code I have and i always get the return code as false.  I tried almost all overloaded methods of concatenate() and same result.  I am 100% sure that the soruce pdfs (PDF1.pdf and PDF2.pdf) are in the correct locations as I don't get any exceptions when I use the FileInputStreams.

I do have the eval license for ASPose.PDF library.

Is there anything that I am doing wrong.  I am using the latest versions of ASPose.PDF library on JDK1.6.

Rgds,

Raj.

 

 

public

class MergePDFs

{

/**

* @param args

*/

publicstaticvoid main( String[] args )

{

OutputStream output =

null ;

InputStream inStream1 =

null ;

InputStream inStream2 =

null ;

try

{

// // initialize ASPose.pdf license.

// License pdfLicense = new License() ;

// pdfLicense.setLicense( "C:\\Temp\\TestPDFs\\Aspose.Pdf.lic" ) ;

// List<InputStream> inStreams = new ArrayList<InputStream>() ;

//

// inStream1 = getFileInputStream( "C:\\Temp\\TestPDFs\\PDF1.pdf" ) ;

// inStream2 = getFileInputStream( "C:\\Temp\\TestPDFs\\PDF2.pdf" ) ;

//

// inStreams.add( inStream1 ) ;

// inStreams.add( inStream2 ) ;

// Concatenate two files

PdfFileEditor editor =

new PdfFileEditor();

// output = new BufferedOutputStream(

// getFileOutputStream( "C:\\Temp\\TestPDFs\\MergedPDF.pdf" ) );

// editor.concatenate( inStream1, inStream2, output);

// boolean code = editor.concatenate( inStreams.toArray( new InputStream[0] ), output ) ;

// boolean code = editor.concatenate(

// new String[] {

// "C:\\Temp\\TestPDFs\\PDF1.pdf",

// "C:\\Temp\\TestPDFs\\PDF2.pdf"

// } ,

// "C:\\Temp\\TestPDFs\\MergedPDF.pdf"

// ) ;

boolean code = editor.concatenate(

"C:\\Temp\\TestPDFs\\PDF1.pdf",

"C:\\Temp\\TestPDFs\\PDF2.pdf",

"C:\\Temp\\TestPDFs\\MergedPDF.pdf"

);

System.

out.println( code ) ;

}

catch(Throwable ex)

{

ex.printStackTrace();

}

finally

{

try { output.close() ; } catch (Throwable t) { ; } ;

try { inStream2.close() ; } catch (Throwable t) { ; } ;

try { inStream1.close() ; } catch (Throwable t) { ; } ;

}

return ;

}

privatestatic InputStream getFileInputStream( String filePath ) throws Exception

{

returnnew FileInputStream( filePath ) ;

}

privatestatic OutputStream getFileOutputStream( String filePath ) throws Exception

{

returnnew FileOutputStream( filePath ) ;

}

}


Viewing all articles
Browse latest Browse all 3131

Trending Articles