Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, vidya.

Asked: September 26, 2019 - 6:16 am UTC

Last updated: April 12, 2021 - 5:19 am UTC

Version: oracle 11g

Viewed 1000+ times

You Asked

Hi,


Can we merge multiple PDF documents into 1 PDF using plsql function?If so please suggest me the solution.





Thank You,

Vidya K
Bangalore


and Connor said...

There is nothing in the database that does that natively.

However, there are third party options in PLSQL that allow it.

https://www.plpdf.com/plpdf-manager-features.php

(I have not tried or tested this product)

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 27, 2019 - 4:21 am UTC

Thank you...

Mr.

Jai, April 11, 2021 - 4:35 pm UTC

you can merge using ITEXT PDF.

Download 1. itext-2.1.5.jar
2.bcmail-jdk14-143.jar
3.bcprov-jdk14-143.jar


1. Load itext-2.1.5.jar into database

open CMD..change directory to folder where jar file exist.

loadjava -user schemname/password@SID itext-2.1.5.jar

* initially most of them will be compiled with errors

2. Load bcmail-jdk14-143.jar into database
loadjava -user schemname/password@SID bcmail-jdk14-143.jar

3. Load bcprov-jdk14-143.jar into database
loadjava -user schemname/password@SID bcprov-jdk14-143.jar

4. Recompile objects in itext-2.1.5

5. create a java object

set define off
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED <SCHEMA_NAME>."mergePDF" as package createPDF_test;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

public class mergePDF {


public static void Create_Pdf(String path, String src) throws IOException, DocumentException {
File fs= new File(path);

if(fs.exists())
{
Date ds = new Date();
Document dc= new Document();
FileInputStream fi= new FileInputStream(path);
PdfReader Existfile= new PdfReader(fi);

FileOutputStream fo= new FileOutputStream(path);

PdfCopy copy = new PdfCopy(dc, fo);
try {
PdfReader newfile = new PdfReader(src);

int newfilenoofpages = newfile.getNumberOfPages();
int existfilenoofpages = Existfile.getNumberOfPages();
dc.open();

for (int l = 1; l <= existfilenoofpages; l++) {
copy.addPage(copy.getImportedPage(Existfile, l));
}

for (int k = 1; k <= newfilenoofpages; k++) {
copy.addPage(copy.getImportedPage(newfile, k));
}

newfile.close();
Existfile.close();
dc.close();
}
catch (DocumentException ex) {
System.out.println("ITextHelper.addPDFToPDF(): can't read output location: " + ex);


} catch (IOException ex) {
System.out.println(ex);
}

}

else if (!fs.exists())
{
Document document = new Document();
PdfCopy copy= new PdfCopy(document,new FileOutputStream(path));
try {

PdfReader pr= new PdfReader(src);

if (pr!=null)
{
int numberofpages= pr.getNumberOfPages();

document.open();
for (int k = 1; k <= numberofpages; k++) {
copy.addPage(copy.getImportedPage(pr, k));

}
}
pr.close();

}
catch (DocumentException ex) {
System.out.println("ITextHelper.addPDFToPDF(): can't read output location: " + ex);


} catch (IOException ex) {
System.out.println(ex);
}

document.close();

}
}



public static void main(String[] args) throws IOException, DocumentException {


}


}


6. create a function to call

CREATE OR REPLACE function <SCHEMA-NAME>.CREATE_PDF_TEST_TEN(p_path in varchar2,p_src in varchar2)
return varchar2
as
language java
name 'createPDF_test.mergePDF.Create_Pdf(java.lang.String,java.lang.String) return String';
/


7. Pass the path and source file in the function






Connor McDonald
April 12, 2021 - 5:19 am UTC

Nice input.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library