Can file extensions be suppressed?

Our source MS Word documents include the document filename in the footer without the filename extension. Upon conversion, the source filename extension (.doc) is displayed in the document footer of the Aspose-generated .PDF document. Is there any way to suppress the extension?


The source Word doc, and generated PDF document are both attached. You can see the filename in the bottom right of the footer in both documents. The PDF document includes “.doc”. The Word doc does not.

Thanks.

Mike Girifalco

Hi Mike,


Thanks for your inquiry. Please use the following code to achieve this:
Document doc = new Document(getMyDir() + “wpp%24150%24150-0114asc.doc”);
DocumentBuilder builder = new DocumentBuilder(doc);

NodeCollection fields = doc.getChildNodes(NodeType.FIELD_START, true);
for (FieldStart start : (Iterable<FieldStart>) fields)
{
if (start.getFieldType() == FieldType.FIELD_FILE_NAME)
{
start.getField().update();
builder.moveToField(start.getField(), false);
builder.write(start.getField().getResult().replace(".doc", “”));
start.getField().remove();
}
}

doc.save(getMyDir() + “out.pdf”);

I hope, this helps.

Best regards,

Thank you for the suggestion. Our development team tried this, but the solution appears to be incompatible with JRE 1.4 and 1.5, which are the Java versions we have running in our environment. See below response.


Is there a JRE 1.5 compatible solution? Also, which version of aspose.words is required for this fix? We are using 14.6.

Thank you.

Mike Girifalco

===Developer response===
<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>The file extension
code is not compatible with application code as application is based on JRE1.4
and when i have change the JRE 1.5 the build failed on application code which
was not compatible with JRE1.5.<span style=“font-size:12.0pt;font-family:
“Times New Roman”,“serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA”>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>I have tried to
compile the code separately with JRE 1.5 but i am getting ClassCastException at
runtime .
<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>
<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>I am not sure which version of aspose jar vendor used for this
solution.<span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Can you please help
us to resolve this issue by providing compatible JRE version and aspose jar
version for this solution.<span style=“font-size:12.0pt;font-family:
“Times New Roman”,“serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:
AR-SA”>
<span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>following exception
thrown when solution code run separately <span style=“font-size:12.0pt;
font-family:“Times New Roman”,“serif”;mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Exception in thread “main”
java.lang.ClassCastException: com.aspose.words.NodeCollection
<span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;mso-fareast-font-family:
Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>

<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;color:red;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>
at Doc2PdfConversion.main(Doc2PdfConversion.java:51)

Hi Mike,


Thanks for your inquiry. The solution was tested using the following Aspose.Words Jar files over Java version 1.7.0_55:

  • aspose-words-14.6.0-jdk15.jar
  • aspose-words-14.6.0-jdk16.jar

Please try executing the following code in your environment and see how it goes.
Document doc = new Document(getMyDir() + “wpp%24150%24150-0114asc.doc”);
DocumentBuilder builder = new DocumentBuilder(doc);

Node[] fields = doc.getChildNodes(NodeType.FIELD_START, true).toArray();
for (int i = 0; i < fields.length; i++)
{
FieldStart start = (FieldStart)fields[i];
if (start.getFieldType() == FieldType.FIELD_FILE_NAME)
{
start.getField().update();
builder.moveToField(start.getField(), false);
builder.write(start.getField().getResult().replace(".doc", “”));
start.getField().remove();
}
}

doc.save(getMyDir() + “out.pdf”);

I hope, this help.

Best regards,