How to convert InputStream to PDF in Spring Java

Hi Team,

I am using below code to convert input stream to PDF conversion and then downloading that PDF file but facing performance issue . it takes 2 to 3 minutes to complete hole process.
Please tell me what’s going wrong in my code snipet.

public void convertToPdf(String policyId,Integer documentId,ServletContext context,ServletOutputStream outputStream,HttpServletResponse response, String pageFlag) throws UnsupportedEncodingException, Exception {
** Utilities.applyLicenseFromFile();**
** PolicyForm policyForm=policyManager.viewPolicyInfo(Integer.parseInt(policyId));**
** if(pageFlag!=null && pageFlag.equalsIgnoreCase(“policyListing”)){**
** documentId=policyForm.getDocumentId(); **
** } **
** LOGGER.info("Inside method convertToPdf() - Conversion Started :::::::::::::::::::::::::::::: ");**
** String fileName = “Policy “+policyForm.getPolicyNumber()+”.html”;**
** String cssFileLink=context.getRealPath("/resources/layoutcss/policyEditor.css");**
** String policyContent = new String(documentManager.openDocumentFromDMS(documentId), “UTF-8”);**
** String html=" "**
** +"


"**
** +“

Policy Details


”+getPolicyDetails(policyForm)**

** +“

Policy Content


”+policyContent**

** +"
"; **
** ConversionHandler conversionHandler = new ConversionHandler(new ConversionConfig());**
** PdfSaveOptions saveOption = new PdfSaveOptions();**
** byte[] bytearr = html.getBytes();**
** response.setContentType(“application/pdf”);**
** response.setHeader(“Content-Disposition”, “attachment; filename=” + “Policy “+policyForm.getPolicyNumber()+”.pdf”);**
** response.setHeader(“Cache-Control”, “no-cache”);**
** ConvertedDocument convertedDocument= conversionHandler.convert(new ByteArrayInputStream(bytearr),fileName,saveOption);**
** GroupDocsOutputStream groupDocsOutputStream = new GroupDocsOutputStream(response.getOutputStream());**
** convertedDocument.save(groupDocsOutputStream);**
** LOGGER.info("Inside method convertToPdf() - Conversion Ended :::::::::::::::::::::::::::::: ");**
** }**

@saras1234,

Can you please share the source file with us? We will then investigate document conversion performance.
As you said that total process (conversion plus downloading) is taking 2-3 minutes. Can you please share your findings about conversion only (aside from downloading time)?
Because if conversion process is taking this long, we have to investigate it. Otherwise, you can change your document downloading logic.
The good thing is we have an open-source project for you ease. You can explore it and enhance it as per your needs. See this video demo.