1

i want to convert docx to pdf using apache-poi and itext 7(pdf calligraph on)

i have tried using other version of itext but they are showing problem of ligature in indic languages

import org.apache.poi.xwpf.converter.pdf.PdfConverter;

import org.apache.poi.xwpf.converter.pdf.PdfOptions;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import org.springframework.util.FileCopyUtils;
import java.io.*;

public class Docx2PdfConverterUsingPOI implements Docx2PdfConverter{
    public byte[] convert(byte[] docxData) {

        byte[] output = null;
        try {
            InputStream isFromFirstData = new ByteArrayInputStream(docxData);

            XWPFDocument document = new XWPFDocument(isFromFirstData);
            PdfOptions pdfOptions = PdfOptions.create();
            // pdfOptions.fontEncoding(BaseFont.IDENTITY_H);
            //make new file in c:\temp\
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            //Options options =


            Options.getTo(ConverterTypeTo.PDF).via(ConverterTypeVia.XWPF).
            subOptions(pdfOptions);
            PdfConverter.getInstance().convert(document, out, pdfOptions);






            document.close();
            return out.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return output;

    }

    public static void main(String args[]){
        Docx2PdfConverterUsingPOI docx2PdfConverterUsingPOI =new

        Docx2PdfConverterUsingPOI();

        String inputFile = "D:\\WORKSPACE\\yogesh\\letters\\out.docx";

        FileInputStream inputStream = null;
        try {

            inputStream = new FileInputStream(new File(inputFile));
            byte[]output =





            docx2PdfConverterUsingPOI.convert(FileCopyUtils.
            copyToByteArray(inputStream));
            FileCopyUtils.copy(output,new
            File("D:\\WORKSPACE\\yogesh\\letters\\out1.pdf"));

            } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

can anyone help me in how to use itext7 with apache poi for my docx to pdf conversion. Also,can anyone explain how apache uses itext to get proper result of conversion(so that i can change the itext maven dependency accordingly)

  • See https://stackoverflow.com/questions/51440312/docx-to-pdf-converter-in-java -- the PdfConverter you are using is out of date – PJ Fanning Aug 23 '19 at 23:13
  • the new version still uses itext 2.1.7. I want to use itext 7(pdfcalligraph on) with it because it solves my indic language problem. – Choupane Pushkar Jayant Aug 24 '19 at 07:22
  • 1
    itext 7 has licensing that discourages its use - you would probably need a commercial license to use it - it should be feasible to fork the opensagres code to work with itext 7 if that's what you want - if you are forking the opensages code, maybe you could use https://en.wikipedia.org/wiki/OpenPDF or https://pdfbox.apache.org/ instead – PJ Fanning Aug 24 '19 at 11:36
  • 1
    You are using pdfCalligraph, which is a commercial add-on of iText, which means that you have a support contract. Please contact iText Software directly for technical support. – Amedee Van Gasse Aug 26 '19 at 10:06
  • 1
    I have contacted them but got no response.I have the support contract.(I have taken 30 days trial). – Choupane Pushkar Jayant Aug 26 '19 at 10:53

0 Answers0