import com.groupdocs.conversion.Converter; import com.groupdocs.conversion.options.convert.PdfConvertOptions; private byte[] convertToPdf(byte[] content, String extension) { try (ByteArrayInputStream inputStream = new ByteArrayInputStream(content); Converter converter = new Converter(inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { // Modern conversion method PdfConvertOptions options = new PdfConvertOptions(); converter.convert(outputStream, options); return outputStream.toByteArray(); } catch (Exception e) { logger.error(“Conversion failed for {}: {}”, extension, e.getMessage()); return null; } }
Suggest an alternative solution
@anandhu122334
It appears that the method you are using for document conversion with the GroupDocs library has been marked as deprecated. To adapt to the latest API changes, you can use a lambda expression for both the input stream and the output stream. Here’s an updated version of your code that reflects this change:
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;
private byte[] convertToPdf(byte[] content, String extension) {
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(content);
Converter converter = new Converter(() -> inputStream, () -> loadOptions);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
// Modern conversion method
converter.convert(() -> outputStream, new PdfConvertOptions());
return outputStream.toByteArray();
} catch (Exception e) {
logger.error("Conversion failed for {}: {}", extension, e.getMessage());
return null;
}
}
In this updated code:
- The
Converter
constructor now accepts lambda expressions for the input and load options.
- The
convert
method also uses a lambda for the output stream.
This approach ensures that you are using the current API and avoids the deprecated methods. If you have any further questions or need additional assistance, feel free to ask!
Does it support byte array of data accessced by
ByteArrayInputStream inputStream = new ByteArrayInputStream(content)
And then use groupDocs Converter
Hello @anandhu122334 ,
Yes, Conversion supports ByteArrayInputStream as input.
The example above is correct and works fine. If you have any further questions, please feel free to ask.