Skip to main content
Participant
February 8, 2024
Question

Internal Server Error when generating DOCX from DOCX

  • February 8, 2024
  • 0 replies
  • 187 views

Hello, I'm trying to generate a filled DOCX document with also a DOCX document as template file in Spring Boot. Everytime I try to build that file it stucks at the line: 

StreamAsset streamAsset = pdfServices.getContent(resultAsset);

I already tried multiple changes in the code but it just wouldn't work. The exact error code is:

com.adobe.pdfservices.operation.exception.ServiceApiException: description ='Fatal error, Please check logs for details.'; requestTrackingId='b2a02fcd-a057-463e-9ec6-ff3a977d3190'; statusCode=500; errorCode=INTERNAL_SERVER_ERROR

and also my whole Java class "GenerateDoc.java":

@PostMapping("/backend/generateDoc")
    public String generateDoc(@RequestBody String request) throws IOException, ServiceApiException, SDKException, ServiceUsageException {

        try {
            JSONObject jsonObject = new JSONObject(request);
            System.out.println("Request: " + request);
            JSONArray jsonArray = jsonObject.getJSONArray("dataList");
            JSONObject jsonDataForMerge = new JSONObject();

            jsonDataForMerge.put("Kunde", jsonArray.getString(12));
            // There are other values but I have to hide them
            InputStream inputStream = Files.newInputStream(new File("src/main/resources/RV-Deutsch.docx").toPath());

            Credentials credentials = new ServicePrincipalCredentials(clientId, clientSecret);

            PDFServices pdfServices = new PDFServices(credentials);

            Asset asset= pdfServices.upload(inputStream, PDFServicesMediaType.DOCX.getMediaType());

            DocumentMergeParams documentMergeParams = DocumentMergeParams.documentMergeParamsBuilder()
                    .withJsonDataForMerge(jsonDataForMerge)
                    .withOutputFormat(OutputFormat.DOCX)
                    .build();

            DocumentMergeJob documentMergeJob = new DocumentMergeJob(asset, documentMergeParams);

            String location = pdfServices.submit(documentMergeJob);
            PDFServicesResponse<DocumentMergeResult> pdfServicesResponse = pdfServices.getJobResult(location, DocumentMergeResult.class);

            Asset resultAsset = pdfServicesResponse.getResult().getAsset();
            StreamAsset streamAsset = pdfServices.getContent(resultAsset);

            String resultPath = "src/main/resources/output.docx";

            OutputStream outputStream = Files.newOutputStream(new File(resultPath).toPath());
            IOUtils.copy(streamAsset.getInputStream(), outputStream);
            outputStream.close();

            return resultPath;
        } catch (ServiceApiException | IOException | SDKException | ServiceUsageException e) {
            throw new RuntimeException(e);
        }
    }

 

For now the DOCX template has only the following content:

{{Kunde}}

This topic has been closed for replies.