public class FieldFileSize extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the size of the current document's file or 0 if the size cannot be determined.
In the current implementation, uses the Document.getOriginalFileName() property to retrieve the file name used to determine the file size.
Examples:
Shows how to display the file size of a document with a FILESIZE field.
Document doc = new Document(getMyDir() + "Document.docx");
Assert.assertEquals(doc.getBuiltInDocumentProperties().getBytes(), 18105);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.insertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
FieldFileSize field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.update();
Assert.assertEquals(" FILESIZE ", field.getFieldCode());
Assert.assertEquals("18105", field.getResult());
// 2 - Kilobytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInKilobytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\k", field.getFieldCode());
Assert.assertEquals("18", field.getResult());
// 3 - Megabytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInMegabytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\m", field.getFieldCode());
Assert.assertEquals("0", field.getResult());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc.save(getArtifactsDir() + "Field.FILESIZE.docx");
| Modifier and Type | Method and Description |
|---|---|
int |
getSwitchType(java.lang.String switchName) |
boolean |
isInKilobytes()
Gets whether to display the file size in kilobytes.
|
void |
isInKilobytes(boolean value)
Sets whether to display the file size in kilobytes.
|
boolean |
isInMegabytes()
Gets whether to display the file size in megabytes.
|
void |
isInMegabytes(boolean value)
Sets whether to display the file size in megabytes.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic boolean isInKilobytes()
Examples:
Shows how to display the file size of a document with a FILESIZE field.
Document doc = new Document(getMyDir() + "Document.docx");
Assert.assertEquals(doc.getBuiltInDocumentProperties().getBytes(), 18105);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.insertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
FieldFileSize field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.update();
Assert.assertEquals(" FILESIZE ", field.getFieldCode());
Assert.assertEquals("18105", field.getResult());
// 2 - Kilobytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInKilobytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\k", field.getFieldCode());
Assert.assertEquals("18", field.getResult());
// 3 - Megabytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInMegabytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\m", field.getFieldCode());
Assert.assertEquals("0", field.getResult());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc.save(getArtifactsDir() + "Field.FILESIZE.docx");
public void isInKilobytes(boolean value)
throws java.lang.Exception
Examples:
Shows how to display the file size of a document with a FILESIZE field.
Document doc = new Document(getMyDir() + "Document.docx");
Assert.assertEquals(doc.getBuiltInDocumentProperties().getBytes(), 18105);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.insertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
FieldFileSize field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.update();
Assert.assertEquals(" FILESIZE ", field.getFieldCode());
Assert.assertEquals("18105", field.getResult());
// 2 - Kilobytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInKilobytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\k", field.getFieldCode());
Assert.assertEquals("18", field.getResult());
// 3 - Megabytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInMegabytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\m", field.getFieldCode());
Assert.assertEquals("0", field.getResult());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc.save(getArtifactsDir() + "Field.FILESIZE.docx");
value - Whether to display the file size in kilobytes.java.lang.Exceptionpublic boolean isInMegabytes()
Examples:
Shows how to display the file size of a document with a FILESIZE field.
Document doc = new Document(getMyDir() + "Document.docx");
Assert.assertEquals(doc.getBuiltInDocumentProperties().getBytes(), 18105);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.insertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
FieldFileSize field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.update();
Assert.assertEquals(" FILESIZE ", field.getFieldCode());
Assert.assertEquals("18105", field.getResult());
// 2 - Kilobytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInKilobytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\k", field.getFieldCode());
Assert.assertEquals("18", field.getResult());
// 3 - Megabytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInMegabytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\m", field.getFieldCode());
Assert.assertEquals("0", field.getResult());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc.save(getArtifactsDir() + "Field.FILESIZE.docx");
public void isInMegabytes(boolean value)
throws java.lang.Exception
Examples:
Shows how to display the file size of a document with a FILESIZE field.
Document doc = new Document(getMyDir() + "Document.docx");
Assert.assertEquals(doc.getBuiltInDocumentProperties().getBytes(), 18105);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
builder.insertParagraph();
// Below are three different units of measure
// with which FILESIZE fields can display the document's file size.
// 1 - Bytes:
FieldFileSize field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.update();
Assert.assertEquals(" FILESIZE ", field.getFieldCode());
Assert.assertEquals("18105", field.getResult());
// 2 - Kilobytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInKilobytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\k", field.getFieldCode());
Assert.assertEquals("18", field.getResult());
// 3 - Megabytes:
builder.insertParagraph();
field = (FieldFileSize) builder.insertField(FieldType.FIELD_FILE_SIZE, true);
field.isInMegabytes(true);
field.update();
Assert.assertEquals(" FILESIZE \\m", field.getFieldCode());
Assert.assertEquals("0", field.getResult());
// To update the values of these fields while editing in Microsoft Word,
// we must first save the changes, and then manually update these fields.
doc.save(getArtifactsDir() + "Field.FILESIZE.docx");
value - Whether to display the file size in megabytes.java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)