@wogus1919 You have specified font file name instead of folder name in your code. Please change this:
new FolderFontSource("/src/main/fonts/NanumGothic.ttf", true)
to this:
new FolderFontSource("/src/main/fonts/", true)
@wogus1919 You have specified font file name instead of folder name in your code. Please change this:
new FolderFontSource("/src/main/fonts/NanumGothic.ttf", true)
to this:
new FolderFontSource("/src/main/fonts/", true)
new FolderFontSource("/src/main/fonts/", true) builder.getFont().setName("Nanum Gothic");
@wogus1919 Please make sure Nanum Gothic font is available. You can implement IWarningCallback to get notification when Aspose.Words cannot find the requested font and substitutes it. For example see the following code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.setFontSettings(new FontSettings());
doc.getFontSettings().setFontsSources(new FontSourceBase[] { new SystemFontSource(), new FolderFontSource("C:\\Temp\\fonts", true) });
builder.getFont().setName("Nanum Gothic");
builder.write("This is Nanum Gothic Text");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("C:\\Temp\\out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
System.out.println(info.getDescription());
}
}
thank you
After installing fonts on the server, the pdf comes out properly.
I have a question. Is there a way to get table height like section.getPageSetup()?
section.getPageSetup();
@wogus1919 As you may know MS Word documents are flow documents and does not contain any information about document layout. The consumer applications like MS Word or Open Office build the document layout on the fly. Aspose.Words has it’s own document layout engine. The facade classes LayoutCollector and LayoutEnumerator that allow to get layout information of document elements.
You can use code like the following to get bounding box of tables in your document:
// Open document
Document doc = new Document("C:\\Temp\\in.docx");
// Create LayoutCollector and LayoutEnumerator classes to get layout information of nodes.
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
// Calculate bounding boxes of table in the document.
Iterable<Table> tables = doc.getChildNodes(NodeType.TABLE, true);
for (Table t : tables)
{
// Skip tables which are in header footer(LayoutCollector and LayoutEnumerator classes do not work with header/footer nodes)
if (t.getAncestor(NodeType.HEADER_FOOTER) != null)
continue;
// Move LayoutEnumerator to the first row
enumerator.setCurrent(collector.getEntity(t.getFirstRow().getFirstCell().getFirstParagraph()));
while (enumerator.getType() != LayoutEntityType.ROW)
enumerator.moveParent();
//Get rectangle of the first row of the table.
Rectangle2D first_rect = enumerator.getRectangle();
// Do the same with last row
enumerator.setCurrent(collector.getEntity(t.getLastRow().getFirstCell().getFirstParagraph()));
while (enumerator.getType() != LayoutEntityType.ROW)
enumerator.moveParent();
// Get rectangle of the last row in the table.
Rectangle2D last_rect = enumerator.getRectangle();
// Union of the rectangles is the bounding box of the table.
Rectangle2D result_rect = first_rect.createUnion(last_rect);
System.out.println("Table rectangle : x=" + result_rect.getX() + ", y=" + result_rect.getY() + ", width=" + result_rect.getWidth() + ", height=" + result_rect.getHeight());
}
Please note, the code is simplified to demonstrate the basic technique and converts only tables placed on a single page. In MS Word tables can span more than one page.
thank you
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.startTable();
// Specify cell border width
builder.getCellFormat().getBorders().setLineWidth(3);
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
builder.insertCell();
builder.write("test");
}
builder.endRow();
}
builder.endTable();
doc.save("C:\\Temp\\out.docx");
There is also a height specification for row size in the word table properties, but there is a row height minimum/fixed function next to it. How do I use the fixation function?
@wogus1919 You can specify row height using RowFormat.Height property and height rule using RowFormat.HeightRule and HeightRule enum.
Please see our documentation to learn how to specify table formatting on Tabel, Row and Cell levels:
https://docs.aspose.com/words/java/applying-formatting/
Can I make a table like this?
@wogus1919 Sure, you can create the tables with merged cells using Aspose.Words. Please see our documentation to learn how to achieve this:
https://docs.aspose.com/words/java/working-with-merged-cells/
thank you
I have two questions.
The document size depend on it’s content. Usually DOCX format is quite compact, since this is a zip archive. But if your document contains data that cannot be compressed well, like large images, fonts, etc, I am afraid, there is no way to reduce the document size. There are few things you can do:
You can load document from stream and save it to stream so there is no limitations from Aspose.Words side from where to load document or where to save them.
How do I use the MAXIMUM maximum?
docx.save(bo, SaveFormat.DOCX.CompressionLevel(MAXIMUM));
Should I do it like the code above?
@wogus1919 Your code should look like this:
OoxmlSaveOptions opt = new OoxmlSaveOptions();
opt.setCompressionLevel(CompressionLevel.MAXIMUM);
doc.save("C:\\Temp\\out.docx", opt);
So you don’t use Save Format??
I save it in two forms: pdf and docx.
PdfSaveOptions options = new PdfSaveOptions();
SaveFormat.DOCX
@wogus1919 Yes, if it is required to specify additional options, you should use the Document.save overload that accepts SaveOptions as the second parameter. Please see our documentation for more information:
https://docs.aspose.com/words/java/specify-save-options/
Are you telling me to do this??
PdfSaveOptions options = new PdfSaveOptions(); options.setCompressionLevel(CompressionLevel.MAXIMUM);
@wogus1919 No. I mean OoxmlSaveOptions, just like I have shown in the code example above:
OoxmlSaveOptions opt = new OoxmlSaveOptions();
opt.setCompressionLevel(CompressionLevel.MAXIMUM);
doc.save("C:\\Temp\\out.docx", opt);
PdfSaveOptions are using when you save document to PDF. OoxmlSaveOptions are used when you save the document to DOCX.
@wogus1919 No. I mean OoxmlSaveOptions, just like I have shown in the code example above:
OoxmlSaveOptions opt = new OoxmlSaveOptions();
opt.setCompressionLevel(CompressionLevel.MAXIMUM);
doc.save("C:\\Temp\\out.docx", opt);
PdfSaveOptions are using when you save document to PDF. OoxmlSaveOptions are used when you save the document to DOCX.