I am trying to find the default font size of a doc/ docx document using apache poi. I have used the XWPFRun class method getFontSize(). But it returns the value -1 if the font size is default. I couldn't find any other method that returns the same in the documentation. Is there a way i can get the "actal" default font size of the document?
In my case,
document.getStyles().getDefaultRunStyles().getFontSize();
solved the problem.
Related
Heyo,
I've just stumbled upon this weird issue with my GLTF import: When loading the file in my three.js viewer, the colors looking different from the original file.
Compare McCudy's viewer:
GLTF file as seen in https://gltf-viewer.donmccurdy.com/
With my three.js viewer:
three.js viewer with ambient light brightness increased unhealthily
And again McCurdy's viewer but set to linear color encoding:
GLTF file as seen in https://gltf-viewer.donmccurdy.com/ with linear encoding
Looks familiar right?
I've already tried what three suggests: changing the color encoding of the renderer to sRGBEncoding but this problem is it doesn't change anything. Regardless of whether I use linear or sRGB encoding, the colors look the same. I checked the renderer and the outputEncoding is applied correctly.
Any idea's to why the setting does not seem to be applied or what else could be the source of the color change?
For information, I'm running a fairly old version of three.js (r97) which for various reasons I cannot update.
In three.js r112, the renderer.outputEncoding property was added, replacing the older renderer.gammaOutput property. In any earlier versions, the equivalent of renderer.outputEncoding = THREE.sRGBEncoding would be:
renderer.gammaOutput = true;
renderer.gammaFactor = 2.2;
If materials have already been rendered before these settings are configured on the renderer, you may also need to set material.needsUpdate = true to recompile them.
I am trying to create from scratch a docx file report, so I am using the python-docx library ver 0.8.10, with great results. When I am adding a header to the document, the header has the default values of "Header from Top:" = 0.5 Inches. I see this value when I have created the docx file and opened it in MS WORD.
So, how can I configure the "Header from Top" and the "Footer from Bottom" default values? For example How can I configure the header to be "Header from Top" = 0.1 inches? Something like header.top_margins = Inches(0.1). I have checked online but haven't found anything related.
Thanks in advance
I think you're looking for Section.header_distance and .footer_distance:
https://python-docx.readthedocs.io/en/latest/api/section.html#docx.section.Section.header_distance
header_distance
Length object representing the distance from the top edge of the page to the top edge
of the header. None if no setting is present in the XML.
I'm loading a simple page with a header and styling created by POI and saved it as test.docx:
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setFontFamily("Arial Narrow");
run.setFontSize(22);
run.setText("Test");
run.getCTR().addNewRPr().addNewHighlight().setVal(STHighlightColor.DARK_RED);
When I load it with docx4j and insert an altChunk then saving the document seems to result in resetting the font size and font family to Calibri and size 11. Which i assume is the default font.
WordprocessingMLPackage wordmlPackage = WordprocessingMLPackage.load(new FileInputStream("test.docx"));
String pageBreak = "<html><body><br style='page-break-after: always; clear:both;' /></body></html>"
wordmlPackage.getMainDocumentPart().addAltChunk(AltChunkType.Html, pageBreak.getBytes());
wordmlPackage.save(new File("I:/local/FinalTestResult.docx"));
So my questions is, is there something I'm missing on why it is doing it and how can I prevent the document from resetting the font when adding a AltChunk?
Using: docx4j version 3.2.0
Edit:
I identified the cause of the change and included the line that's causing the issue on the original post:
run.getCTR().addNewRPr().addNewHighlight().setVal(STHighlightColor.DARK_RED);
It looks like if i add this to a run, it's reseting the fonts. Not sure why though.
I'm a newbie of apache poi, and am using poi to write some data to docx file. Recently I encountered a problem of font, hope any body can give me some help.
I began the writing with an empty word file named empty.docx, as following.
InputStream input = getClass().getClassLoader().getResourceAsStream("empty.docx");
XWPFDocument document = new XWPFDocument(input);
In the empty.docx the default font is 'Arial', that means if you add any content they will inherit this font as long as you don't change the font manually.
But after I filled the content and write it to a new docx file,the default font was changed to 'Century'.
OutputStream output = new FileOutputStream("output.docx");
document.write(output);
I want to change it back to 'Arial', but after a lot of search only found the methods to set font of XWPFRun.
run.getCTR().getRPr().getRFonts().setEastAsia(eastAsiaFontName);
run.getCTR().getRPr().getRFonts().setHAnsi(normalFontName);
I want to know if there is any method to change the global font of the whole document?
You can set the default font of the document like this (using your variable names):
XWPFStyles styles = document.createStyles();
CTFonts fonts = CTFonts.Factory.newInstance();
fonts.setEastAsia(eastAsiaFontName);
fonts.setHAnsi(normalFontName);
styles.setDefaultFonts(fonts);
I am currently stuck at how I set the default font size. That's why I found this question... The XWPFStyles class has a member "CTStyles ctStyles" with which it would be possible to define any property defined in the XML spec. But unfortunately it has only a public setter, but no getter.
I have written an application using Python 2.7 and Tkinter that edits *.docx files. In the Text control where the user is able to write text, I can change the font family and fontsize with tag_add and tag_config. Now I need to write this to new *.docx file. How can I retrieve fontfamily and fontsize that were set in several of the text ranges?
My best guess is to get tag from range and later try to get font from this, but I'm not sure.
I have just solved my problem myself :)
Maybe anyone will need it somewhen. You can read any applied attribute from a tag. To do this, you have to use tag_cget method:
selectedFont = textBox.tag_cget("tagName", 'font')
Now, when we got the font from specially tag, we can get from it other attributes by the same way:
fontFamily = selectedFont.cget('family')
It works! ;)