Way to find the current document name

I’m evaluating Aspose and my basic use case is to be able to load a document and save it with a new name and PDF format.

However I do not see APIs to get the current name of the document or its format. I see APIs to get the original name, but not the current one
docCon.getOriginalFileName()

Am sure it is available somewhere, any pointers?

@aspose1212,

Please try using the following code to detect file format and save Word document to PDF with a new name:

Document doc = new Document("E:\\temp\\in.docx");
FileFormatInfo info = FileFormatUtil.detectFileFormat("E:\\temp\\in.docx");
System.out.println(LoadFormat.getName(info.getLoadFormat()));
doc.save("E:\\Temp\\any name.pdf");

Thanks for responding, my Use Case is slightly different - How can I find the name extension of the file that I’m not saving on the disk, but just have it in memory?

Blockquote
@Test
public void testDocumentGeneration() throws Exception{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln(“Aspose Sample Content for Word file.”);

    doc.save("Aspose_NewDoc",SaveFormat.DOCX);

    //1. Want to find the name of the
    String originalName = doc.getOriginalFileName();
    int originalFormat = doc.getOriginalLoadFormat();
    System.out.println("originalName: " + originalName + ", originalFormat:" + originalFormat);

    doc.save("Aspose_PDF",SaveFormat.PDF);
    // want to find the current file name and format
}

Blockquote

@aspose1212,

Please use the following code to detect the file format of document stored in memory stream:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Aspose Sample Content for Word file.");

ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.RTF);

InputStream inStream = new ByteArrayInputStream(baos.toByteArray());

FileFormatInfo info = FileFormatUtil.detectFileFormat(inStream);
System.out.println(LoadFormat.getName(info.getLoadFormat()));