![]() |
#1 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
Change to DOCX output template
I have been using Calibre to convert EPUB/MOBI files to DOCX files, and for the most part it works well for my needs. Is it possible to change the DOCX output template in Calibre to one I use to create new documents in Word (in my case, Word 2010)?
For instance, one of the options I set in "Options -> Advanced -> Image Size and Quality" is to check the box "Do not compress images in file". The DOCX files that are generated by Calibre have this check box cleared. It would be great to have some of these options set to my preferences without having to remember to edit each one before modifying the DOCX output file. Last edited by mfm-ca; 04-10-2017 at 01:13 PM. |
![]() |
![]() |
![]() |
#2 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
@mfm-ca - rather than adding word template settings selectively to the DOCX Output preferences settings, a better solution might be to put the template (DOTX) calibre uses into the [. . .]\Calibre2\resources\templates folder.
Then one could copy it to the resources/templates folder in calibre's configuration directory, make it writeable, and modify to suit one's individual needs. This approach is known as using 'resource overrides', there's a para or two about in the calibre FAQ If present, the DOCX Output plugin would use the override DOTX, otherwise it would use the one in \Calibre2\resources\templates. FWIW : when I want to get something into Word (I go the other way 10-20 times a day) I convert to RTF. I get a more consistent result by going to RTF than going straight to DOCX-- 'consistent' is my watchword for most things, invariably trumps wasting time seeking perfection. The first things I do to an RTF are: attach one of my own Word templates: strip/replace embellishments, strip out superfluous whitespace and new lines and then save as DOCX. I remove the RTF once I have a decent DOCX. I've been using RTF as the route to DOCX since well before Kovid developed the DOCX Input/Output plugins, and I've been using most the macros for 10-20 years. So, I've never even bothered to wonder why going straight to DOCX doesn't seem to suit me. It could well be the template that's attached to the DOCX. BR |
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
Quote:
|
|
![]() |
![]() |
![]() |
#4 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
It can't be done today because there isn't a DOTX in the Calibre2/resources directory to override. The built-in plugins (like DOCX Output) aren't visible in the calibre install folder (I think they're squirreled away in pylib.zip). You could download the source and implement something for yourself, see ==>> Setting up a calibre development environment I'm sure Kovid will see this thread in the next day or two and comment as to the feasibility of implementing a DOTX override. But it may not happen immediately, because Kovid has his head down and tail up getting calibre version 3.0 ready for beta testing ![]() BR |
|
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
@BetterRed
Thank you for taking the time to respond to my thread (twice!). I am usually pretty good about searching for information, but for some reason, I kept missing the customizing plugins section. I will check out the link provided to see if I want to attempt some customization on my own, or whether it even looks possible. Could be fun (he says without the aid of alcohol!). ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,158
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There is no template involved in docx output. Your best bet is to run from source and make the change, which should be a pretty trivial two line change to the create_skeleton() function
|
![]() |
![]() |
![]() |
#7 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
In that case I would do it with a Word macro, and make it accessible from the quick access (title bar) tool bar (I have a menu of several).
Code:
Sub AttachMyTemplate()
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "templatepath"
.XMLSchemaReferences.AutomaticValidation = False
.XMLSchemaReferences.AllowSaveAsXMLWithoutValidation = False
End With
End Sub
|
![]() |
![]() |
![]() |
#8 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
@BetterRed,
The code you provided is similar to one of my attempts (attaching a template). The styles update, but the options under the File menu appear unchanged. One parameter I am interested in, "File -> Options -> Advanced -> Image Size and Quality -> Do not compress images in file" (within Word), remains unchanged. I tried two different template files that have this option checked, but it isn't carried over. |
![]() |
![]() |
![]() |
#9 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Arrgh, we are at sixes and sevens here - It's so long since I did any changes to my Word setup, or anyone else's I forgot where things were
I'm not sure how to set a default value for that setting. Try creating a new DOTX (just clone normal.dotx with a different name), open it, check the option and save the DOTX. Now attach that DOTX to a document and see if the option is checked. If it's not then I'm stumped. There must be a way tho' BR Last edited by BetterRed; 04-11-2017 at 02:54 AM. |
![]() |
![]() |
![]() |
#10 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
Still the same result. The styles are updated, but the advanced options remain unchanged.
I performed a test where I converted a DOCX (with the above option checkbox cleared) to an RTF, then back to DOCX. The latter DOCX has the checkbox set, so the conversion from RTF to DOCX required creating a "new" DOCX, which is picking up this setting from my default template. The conversion from EPUB to RTF in Calibre doesn't set the above checkbox, so that's no help. I've also found myself doing more work getting an RTF to my desired state than I do with DOCX coming from Calibre. Having said that, once in a while I get a DOCX generated from Calibre where I get an error opening. Most times I can track it down to some strange EPUB coding, but I've had to switch to EPUB->RTF conversion just to get a document I can work with in Word. |
![]() |
![]() |
![]() |
#11 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
You may have hit upon one of the reasons I've 'remained loyal' to doing EPUB->RTF conversions, apart from being tooled-up to deal with RTF:
BR |
![]() |
![]() |
![]() |
#12 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
Thanks again for your help. I can always go back to my old process where I change this field manually, but it needs to be done first before any updates are saved in the DOCX.
I have reviewed the comments made by Kovid. The element in question is "doNotAutoCompressPictures" and is located in document.settings (settings.xml). Currently, Calibre is not generating this structure within the output DOCX. Looking at create_skeleton (within ..\src\calibre\ebooks\docx\writer\container.py), I suspect making this change is going to take more than adding a couple of lines of code. If I had to guess, opening an RTF in Word uses your default setting for this and other options as I don't believe the RTF structure has these fields. You can actually edit the RTF in Word, uncheck this option, save the RTF and exit, and when you re-open the RTF, this option will be checked again. Last edited by mfm-ca; 04-11-2017 at 06:37 PM. |
![]() |
![]() |
![]() |
#13 | ||
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,608
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
Quote:
Most of these 'anomalies' seem to stem from having to maintain backwards compatibility. Have you looked at later versions of Office - maybe they've updated it to something more sensible/intuitive. BR |
||
![]() |
![]() |
![]() |
#14 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,158
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If it is in a separate file, it is even simpler -- probably needs only a single line. Look around line 250 in container.py (the same file that has create_skeleton)
|
![]() |
![]() |
![]() |
#15 |
Enthusiast
![]() Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
|
I've copied the Calibre source to my PC, and I have successfully performed the "Hello world!" test. I think any further questions I have on this topic I will submit to the Development forum.
Thanks again everyone. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Convert EPUB to DOCX [Change Default Margins] | Lassox | Conversion | 3 | 04-12-2017 10:03 PM |
Change filename template in Calibre's library | 8140david | Library Management | 3 | 09-25-2016 11:39 AM |
How to change the "inline TOC" template? | Phssthpok | Editor | 15 | 12-06-2014 11:09 AM |
MOBI -> EPUB: Change cover template? | Rev. Bob | Conversion | 3 | 03-22-2013 09:51 PM |
DOCX Input and DOCX Metadata Reader | SauliusP. | Development | 5 | 06-15-2012 02:17 AM |