Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 08-04-2025, 09:37 PM   #1
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
Posts: 33
Karma: 10
Join Date: Apr 2017
Device: PC
DOCX Output setting for image compression

When creating a DOCX from any other eBook format, the following setting is generated by Calibre:

File -> Options -> Advanced -> Image Size and Quality

Under this section, there is a checkbox for:

"Do not compress images in file"

This option is unchecked, meaning images are compressed. I would like Calibre to be able to generate a DOCX with this option checked. Where in the source is this setting generated in Calibre?

Note that my Normal.dotm template has this option checked, so any blank DOCX I create will have this option checked. But those DOCX coming from Calibre will not.
mfm-ca is offline   Reply With Quote
Old 08-04-2025, 10:39 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,410
Karma: 27757236
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There is no such setting. I am guessing the setting you are referencing comes from Word and it controls how word will compress images when the doc file is saved in it. As far as I know thisis not a setting that can be controlled in the DOCX format itself.
kovidgoyal is offline   Reply With Quote
Old 08-05-2025, 12:38 AM   #3
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,777
Karma: 30237628
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Into a blank document which has your preferred settings i.e. "Do not compress images in file" is checked, try using Word->Insert->Object>Text File on the DOCX that calibre creates.

LO Writer probably has something similar.

Not Tested

BR
BetterRed is online now   Reply With Quote
Old 08-05-2025, 05:35 AM   #4
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
Posts: 33
Karma: 10
Join Date: Apr 2017
Device: PC
Quote:
Originally Posted by BetterRed View Post
Into a blank document which has your preferred settings i.e. "Do not compress images in file" is checked, try using Word->Insert->Object>Text File on the DOCX that calibre creates.

LO Writer probably has something similar.

Not Tested

BR
That method does work. In trying to automate it with my batch files and Word macros, I would need to account for the varying page sizes.

I seem to have asked this question about eight years ago. Whoops!

Anyway, for the past eight years, I have been modifying a copy of the code and linking to it. Not many changes are required. Six lines of code in one file and one line of code in another file (plus one line for __init__.py to print a message indicating I am using a code-tweaked version). This code is needed because Calibre does not include the standard settings.xml file within the created DOCX file structure.

My main issue is every time there is a new version of Calibre released, I have to download and update the code. So, while I can get Calibre updated that was installed into Windows regularly, I'm still linked to an older version of Calibre until I re-download the matching code, make the appropriate changes, and adjust the environment variable in Windows.

Not the end of the world. This would be easier if I could do this in a Word macro. Outside of a brute-force method of inserting the document into a blank document, I don't see how to do this in a macro. I toyed with the idea of modifying the XML files within the DOCX, but automating it seems to be beyond my pay grade.

Thanks for the help.
mfm-ca is offline   Reply With Quote
Old 08-05-2025, 07:54 AM   #5
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,777
Karma: 30237628
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Pretty sure you could do it via a Word COM add-in, I'm running a couple of such addins — EPUB Tools and Transtools.

EPUB Tools was last released in Mar 2018, not only does it work on latest Office 365… it works better than it ever did. Function-wise, all the features I use work just like they always did, performance-wise: faster, smoother, less likely to wedge… in fact it's ages since it did.

BR
BetterRed is online now   Reply With Quote
Old 08-07-2025, 03:08 AM   #6
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
Posts: 33
Karma: 10
Join Date: Apr 2017
Device: PC
Quote:
Originally Posted by kovidgoyal View Post
There is no such setting. I am guessing the setting you are referencing comes from Word and it controls how word will compress images when the doc file is saved in it. As far as I know thisis not a setting that can be controlled in the DOCX format itself.
Actually, I don't believe this to be true. A standard DOCX format contains the file \word\settings.xml. The setting for not compressing images is stored there, by document.

When settings.xml is missing from the DOCX, like it is for those generated by Calibre, Word will populate a default settings.xml file within the DOCX file structure that gets written when the document is saved. It also adds an entry to \word\_rels\document.xml.rels to link to the settings.xml file. What I don't know is where Word gets the default format for settings.xml when it does not exist in a Word document that is opened and later saved.

My Normal.dotm has a settings.xml file with "<w:doNotAutoCompressPictures/>" buried in the XML. When a new Word document is created via Windows Explorer or by opening a blank document in Word, settings.xml is carried over with the above XML included.

If Calibre ever adds the settings.xml file to the output DOCX file structure, then my future edits would be isolated to the single code addition to input the above option. As it is, I think my edits are overlooking a few details when inserting settings.xml into the DOCX file structure so that I can set the above option.

Okay, I think I've beaten this into the ground enough.

Last edited by mfm-ca; 08-07-2025 at 12:04 PM.
mfm-ca is offline   Reply With Quote
Old 08-07-2025, 08:22 PM   #7
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,777
Karma: 30237628
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by mfm-ca View Post
Actually, I don't believe this to be true. A standard DOCX format contains the file \word\settings.xml. The setting for not compressing images is stored there, by document.

When settings.xml is missing from the DOCX, like it is for those generated by Calibre, Word will populate a default settings.xml file within the DOCX file structure that gets written when the document is saved. It also adds an entry to \word\_rels\document.xml.rels to link to the settings.xml file. What I don't know is where Word gets the default format for settings.xml when it does not exist in a Word document that is opened and later saved.

My Normal.dotm has a settings.xml file with "<w:doNotAutoCompressPictures/>" buried in the XML. When a new Word document is created via Windows Explorer or by opening a blank document in Word, settings.xml is carried over with the above XML included.

If Calibre ever adds the settings.xml file to the output DOCX file structure, then my future edits would be isolated to the single code addition to input the above option. As it is, I think my edits are overlooking a few details when inserting settings.xml into the DOCX file structure so that I can set the above option.

Okay, I think I've beaten this into the ground enough.
Suggestion: in Preferences->Conversion->Output options->DOCX: provide additional option Inject this settings.xml file, into to which user specifies a <path to the file> they want.

I'm pretty sure I would make use of it.

I note that calibre does inject a webSettings.xml file into the DOCX files it creates.

BR
BetterRed is online now   Reply With Quote
Old 08-07-2025, 09:27 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,410
Karma: 27757236
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
webSettings are needed for the actual document content, for instance calibre includes it to allow use of PNG files. settings is not needed for content, for example, the OP's request is for a setting to control the behavior of Word, a particular program used to view DOCX files. As a general rule I avoid this kind of thing as that way lies madness.

I could of course allow users to import their own settings.xml during conversion, but that is an extremely niche feature unuseable by most people, just have a look at the kinds of things present in settings.xml, for example:
https://python-docx.readthedocs.io/e.../settings.html
kovidgoyal is offline   Reply With Quote
Old 08-08-2025, 02:00 AM   #9
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
Posts: 33
Karma: 10
Join Date: Apr 2017
Device: PC
Quote:
Originally Posted by BetterRed View Post
Suggestion: in Preferences->Conversion->Output options->DOCX: provide additional option Inject this settings.xml file, into to which user specifies a <path to the file> they want.

I'm pretty sure I would make use of it.

I note that calibre does inject a webSettings.xml file into the DOCX files it creates.

BR
That would be pretty nice, but I think Kovid is right. That would require a fair amount of work to address a very small demand.

I have two options:

(1) Keep modifying the Calibre code to insert the settings.xml code along with the code for compressing images option. It is an annoyance, but it works. My only concern is I am not sure I am addressing all of the code that needs to be touched. I've read about "serializing" the XML files, whatever that means. I am currently not doing that with settings.xml, but the DOCX files have been loading into Word without errors and my option has been set. I know enough to be dangerous, but nowhere near enough to be an expert.

(2) Within a batch file: (a) let the unmodified Calibre software generate the DOCX; (b) open the DOCX in Word and force a SaveAs which would get the document updated to my version of Word plus insert a default settings.xml file; (c) use a tool like 7-Zip to overwrite the settings.xml file in the DOCX with one that has the compressing images option; (d) execute my normal Word macros to run a first-pass to clean up the DOCX formatting and insert my preferred style set and good quality cover image.
mfm-ca is offline   Reply With Quote
Old 08-08-2025, 06:03 AM   #10
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,777
Karma: 30237628
Join Date: Mar 2012
Location: Sydney Australia
Device: none
I don't convert to DOCX often enough to warrant automation. I attach one of three of my templates to DOCX produced by calibre and take it from there.

However, go into CoPilot and ask:

Quote:
MS Word: change default value for Options->Advanced->Image Size and Quality->Do not compress images in file to CHECKED
Should provide 3 answers, one of which may be useful.

BR

Last edited by BetterRed; 08-08-2025 at 06:16 AM.
BetterRed is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calibre input docx output epub image issue JeanDolphin Conversion 1 12-24-2023 09:40 PM
Cover image compression ownedbycats Calibre 7 01-23-2021 08:41 AM
2.47 - Image compression not working jlynton Calibre 0 12-25-2015 08:40 AM
MOBI Output Compression? sirbruce Calibre 6 06-14-2009 07:10 PM
MOBI Output Compression? sirbruce Calibre 4 03-27-2009 10:51 AM


All times are GMT -4. The time now is 05:33 PM.


MobileRead.com is a privately owned, operated and funded community.