i'm using iText 2.1.5 to merge 2 PDF files. My problem is, when the concatenated pdf is generated, all fonts used in both pdf are duplicated. Is there a better way to handle this, so that the fonts only get embedded once ?
source code :
public class GroupingPDF {
public static final String RESULT = "/home/asagaama/Documents/groupementpdf/get/concatenated.pdf";;
public static void main(String[] args) {
try {
String[] files = {
"/home/asagaama/Documents/groupementpdf/get/1.pdf",
"/home/asagaama/Documents/groupementpdf/get/2.pdf" };
Document document = new Document();
PdfSmartCopy pdfSmartCopy = new PdfSmartCopy(document,
new FileOutputStream(RESULT));
document.open();
PdfReader reader;
int n;
// loop over the documents you want to concatenate
for (int i = 0; i < files.length; i++) {
reader = new PdfReader(files[i]);
// loop over the pages in that document
n = reader.getNumberOfPages();
for (int page = 0; page < n;) {
pdfSmartCopy.addPage(pdfSmartCopy.getImportedPage(reader,
++page));
}
}
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}