Hello,
I’m trying to obtain information regarding the document I’m trying to convert to a PDF.
I would like to know if I’m processing a landscape or portrait document.
I’m getting the following error:
Failed to generate pdf for document ‘PwC Config.docx’ - class com.groupdocs.conversion.contracts.documentinfo.WordprocessingDocumentInfo cannot be cast to class com.groupdocs.conversion.contracts.documentinfo.PdfDocumentInfo (com.groupdocs.conversion.contracts.documentinfo.WordprocessingDocumentInfo and com.groupdocs.conversion.contracts.documentinfo.PdfDocumentInfo are in unnamed module of loader com.mendix.container.deployment.internal.Interpreters$ClassLoaders$$anon$1 @6bca7e0d)
code:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.contracts.documentinfo.*;
import com.mendix.core.Core;
import com.mendix.logging.ILogNode;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
public class ConvertToPDF extends CustomJavaAction<java.lang.Void>
{
private IMendixObject __InputFile;
private system.proxies.FileDocument InputFile;
private IMendixObject __OutputFile;
private system.proxies.FileDocument OutputFile;
public ConvertToPDF(IContext context, IMendixObject InputFile, IMendixObject OutputFile)
{
super(context);
this.__InputFile = InputFile;
this.__OutputFile = OutputFile;
}
@java.lang.Override
public java.lang.Void executeAction() throws Exception
{
this.InputFile = __InputFile == null ? null : system.proxies.FileDocument.initialize(getContext(), __InputFile);
this.OutputFile = __OutputFile == null ? null : system.proxies.FileDocument.initialize(getContext(), __OutputFile);
// BEGIN USER CODE
ILogNode logger = Core.getLogger("ConvertToPDF");
try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
Converter converter = new Converter(Core.getFileDocumentContent(getContext(), __InputFile));
PdfConvertOptions options = new PdfConvertOptions();
converter.convert(outputStream, options);
IDocumentInfo info = converter.getDocumentInfo();
PdfDocumentInfo pdfInfo = (PdfDocumentInfo) info;
//logger.info("Is Landscape: " + pdfInfo.isLandscape());
//logger.info(pdfInfo.getHeight());
//logger.info(pdfInfo.getWidth());
Core.storeFileDocumentContent(getContext(), __OutputFile, new ByteArrayInputStream(outputStream.toByteArray()));
} catch (IOException e) {
logger.error(e.getMessage());
}
return null;
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "ConvertToPDF";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
Can anyone tell me where I’m going wrong, I’m new to Java so any help would be appreciated.
Regards
Adrian