Update PDF file does not support special characters

0
Hello everyone,   I have a problem with Java action from marketplace module PDF Form Editor. I want to fill the PDF form with values from my application. It works fine, unless I use special character. That is problem for me because I am from Czech republic and we use characters like "ě" "č" "ř" in lot of words. I thought that problem is in file encoding. So I tried to force it to use UTF-8. It did not help. Can you please help me with this?   Microflow where I call Java action "Update PDF file":   Java action "Update PDF file":  // This file was generated by Mendix Studio Pro. // // WARNING: Only the following code will be retained when actions are regenerated: // - the import list // - the code between BEGIN USER CODE and END USER CODE // - the code between BEGIN EXTRA CODE and END EXTRA CODE // Other code you write will be lost the next time you deploy the project. // Special characters, e.g., é, ö, à, etc. are supported in comments. package pdfformeditor.actions; import java.io.InputStream; import java.util.List; import com.mendix.core.Core; import com.mendix.systemwideinterfaces.core.IContext; import com.mendix.systemwideinterfaces.core.IMendixObject; import com.mendix.webui.CustomJavaAction; import com.timeseries.mendix.pdfeditor.dto.ErrorDto; import com.timeseries.mendix.pdfeditor.dto.UpdateRequestDto; import com.timeseries.mendix.pdfeditor.service.PdfService; import org.apache.pdfbox.pdmodel.PDDocument; import pdfformeditor.proxies.ErrorNP; import pdfformeditor.proxies.UpdateRequestNP; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.toList; public class JA_UpdateFields extends CustomJavaAction<java.util.List<IMendixObject>> { /** @deprecated use inputDocument.getMendixObject() instead. */ @java.lang.Deprecated(forRemoval = true) private final IMendixObject __inputDocument; private final system.proxies.FileDocument inputDocument; /** @deprecated use outputDocument.getMendixObject() instead. */ @java.lang.Deprecated(forRemoval = true) private final IMendixObject __outputDocument; private final system.proxies.FileDocument outputDocument; /** @deprecated use com.mendix.utils.ListUtils.map(updateRequestList, com.mendix.systemwideinterfaces.core.IEntityProxy::getMendixObject) instead. */ @java.lang.Deprecated(forRemoval = true) private final java.util.List<IMendixObject> __updateRequestList; private final java.util.List<pdfformeditor.proxies.UpdateRequestNP> updateRequestList; private final java.lang.Boolean flattenForm; public JA_UpdateFields( IContext context, IMendixObject _inputDocument, IMendixObject _outputDocument, java.util.List<IMendixObject> _updateRequestList, java.lang.Boolean _flattenForm ) { super(context); this.__inputDocument = _inputDocument; this.inputDocument = _inputDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), _inputDocument); this.__outputDocument = _outputDocument; this.outputDocument = _outputDocument == null ? null : system.proxies.FileDocument.initialize(getContext(), _outputDocument); this.__updateRequestList = _updateRequestList; this.updateRequestList = java.util.Optional.ofNullable(_updateRequestList) .orElse(java.util.Collections.emptyList()) .stream() .map(updateRequestListElement -> pdfformeditor.proxies.UpdateRequestNP.initialize(getContext(), updateRequestListElement)) .collect(java.util.stream.Collectors.toList()); this.flattenForm = _flattenForm; } @java.lang.Override public java.util.List<IMendixObject> executeAction() throws Exception { // BEGIN USER CODE requireNonNull(inputDocument, "inputDocument is required"); requireNonNull(outputDocument, "outputDocument is required"); requireNonNull(updateRequestList, "updateRequestList is required"); if (!inputDocument.getHasContents(context())) { throw new IllegalArgumentException("The document doesn't have contents"); } try (InputStream fileDocumentContent = Core.getFileDocumentContent(context(), inputDocument.getMendixObject()); PdfService pdfService = new PdfService(PDDocument.load(fileDocumentContent))) { List<ErrorDto> errorDtoList = pdfService.updateFields(convertUpdateRequestsToDto(updateRequestList), flattenForm); if (errorDtoList.isEmpty()){ JA_UpdateField.writePdf(pdfService, outputDocument, context()); return null; } else return convertErrorsFromDto(errorDtoList, context()); } // END USER CODE } /** * Returns a string representation of this action * @return a string representation of this action */ @java.lang.Override public java.lang.String toString() { return "JA_UpdateFields"; } // BEGIN EXTRA CODE public static List<UpdateRequestDto> convertUpdateRequestsToDto(List<UpdateRequestNP> inputList) { return inputList.stream() .map(updateRequestNP -> new UpdateRequestDto(updateRequestNP.getFullyQualifiedName(), updateRequestNP.getValue())) .collect(toList()); } public static List<IMendixObject> convertErrorsFromDto(List<ErrorDto> inputList, IContext context) { return inputList.stream() .map(dto -> convertErrorFromDto(dto, context)) .map(ErrorNP::getMendixObject) .collect(toList()); } public static ErrorNP convertErrorFromDto(ErrorDto dto, IContext context) { ErrorNP mxNp = new ErrorNP(context); mxNp.setFullyQualifiedName(dto.getFullyQualifiedName()); mxNp.setMessage(dto.getMessage()); mxNp.setException(dto.getException()); return mxNp; } // END EXTRA CODE }  
asked
1 answers
1

The problem is not your Java code but the font you are using. Try using a custom font that support international characters. See the documentation here: https://docs.mendix.com/refguide/style/#custom-fonts

Do try the font first to check those custom characters. It is surprising how many fonts do not support those characters.

 

Regards,

Ronald

answered