As an AI Language model, I cannot perform the required action. However, here is an example of how you can use Aspose.Words for Java to convert a Microsoft Word document to PDF format:
First, download the Aspose.Words for Java library from the official website or Maven Repository.
As an AI language model, I am not sure what you mean by an "output type". However, I assume you want to convert a Word document to PDF format using Aspose.Words for Java and retrieve the PDF document as a byte array instead of saving it to a file.
You can use the ByteArrayOutputStream class in conjunction with Aspose.Words and Aspose.PDF for Java to achieve this. Here is some sample code that demonstrates how to do this:
User
use aspose-cells-21.11 convert word to pdf output
Assistant
Aspose.Cells is a library primarily intended for working with Microsoft Excel documents, not Word documents. As for Word to PDF conversions, Aspose.Words is the appropriate library to use.
That being said, if you have a Word document that contains Excel tables or charts and you want to convert it to PDF format using Aspose.Cells, you can use the following sample code as a starting point:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
PdfSaveOptions saveOptions = new PdfSaveOptions();
Set the output PDF file format using the SaveFormat class:
saveOptions.setSaveFormat(SaveFormat.PDF);
Save the Word document to PDF format using the doc.save() method:
doc.save("output.pdf", saveOptions);
Finally, run the Java program to convert the Microsoft Word document to PDF format.
Note: Before running the program make sure that you have access to both Word Document and PDF files in the system.
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.aspose.pdf.devices.PdfSaveOptions;
import com.aspose.pdf.facades.PdfConverter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class WordToPdfConverter {
public static byte[] convertToPdf(byte[] wordDoc) throws IOException {
// load Word document from a byte array
ByteArrayInputStream input = new ByteArrayInputStream(wordDoc);
Document doc = new Document(input);
// set PDF save options
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setSaveFormat(SaveFormat.PDF);
// convert Word document to PDF
ByteArrayOutputStream output = new ByteArrayOutputStream();
doc.save(output, saveOptions);
// load PDF document from the output byte array
byte[] pdfDoc = output.toByteArray();
PdfConverter converter = new PdfConverter();
converter.bindPdf(new ByteArrayInputStream(pdfDoc));
// extract PDF pages as images and append them to a new PDF document
ByteArrayOutputStream finalOutput = new ByteArrayOutputStream();
converter.doConvert();
converter.saveAsTIFF(finalOutput);
// return the final PDF document as a byte array
return finalOutput.toByteArray();
}
}
Note that this code loads a Word document from a byte array, converts it to a PDF document, and then extracts the PDF pages as images before appending them to a new PDF document. Finally, the code returns the byte array of the final PDF document. You can modify this code to suit your specific requirements.
import com.aspose.cells.Workbook;
import com.aspose.cells.WorkbookRender;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class WordToPdfConverter {
public static byte[] convertToPdf(byte[] wordDoc) throws IOException {
// load Word document from a byte array
ByteArrayInputStream input = new ByteArrayInputStream(wordDoc);
Document doc = new Document(input);
// save Word document to a temporary file
ByteArrayOutputStream tempFile = new ByteArrayOutputStream();
doc.save(tempFile, SaveFormat.DOCX);
// load temporary file into an Aspose.Cells Workbook
ByteArrayInputStream tempInput = new ByteArrayInputStream(tempFile.toByteArray());
Workbook workbook = new Workbook(tempInput);
// create an instance of the WorkbookRender class
WorkbookRender wr = new WorkbookRender(workbook, new PdfSaveOptions());
// set rending options
wr.setHideAutoFilterDropDowns(true);
wr.getSaveOptions().setOnePagePerSheet(true);
// render workbook to PDF
ByteArrayOutputStream output = new ByteArrayOutputStream();
wr.toPdf(output);
// return the PDF document as a byte array
return output.toByteArray();
}
}
In this code, we first load the Word document from a byte array and save it to a temporary file in DOCX format (which can be opened by Aspose.Cells). Next, we load the temporary file into an Aspose.Cells Workbook and use the WorkbookRender class to convert it to PDF format. Finally, we return the resulting PDF document as a byte array.
Note that this code assumes that the Word document contains an Excel table or chart that is supported by Aspose.Cells.