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 04-10-2017, 11:34 AM   #1
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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.
mfm-ca is offline   Reply With Quote
Old 04-10-2017, 05:37 PM   #2
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: 20,611
Karma: 26954694
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
BetterRed is offline   Reply With Quote
Advert
Old 04-10-2017, 06:10 PM   #3
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
Posts: 28
Karma: 10
Join Date: Apr 2017
Device: PC
Quote:
Originally Posted by BetterRed View Post
@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.
Sorry I wasn't clear, but your suggestion is exactly what I was looking for as an option. The problem is, I don't see the instructions in the calibre FAQ or anywhere else to implement a 'resource override' in calibre. Also, I see nothing in \Calibre2\resources\templates folder that I believe is the DOCX Output plugin.
mfm-ca is offline   Reply With Quote
Old 04-10-2017, 07:02 PM   #4
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: 20,611
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by mfm-ca View Post
Sorry I wasn't clear, but your suggestion is exactly what I was looking for as an option. The problem is, I don't see the instructions in the calibre FAQ or anywhere else to implement a 'resource override' in calibre. Also, I see nothing in \Calibre2\resources\templates folder that I believe is the DOCX Output plugin.
Firstly, I gave you a bum steer, it's not in the FAQ, it's in the Customising section of the manual ==>> Overriding icons, templates, et cetera. Sorry about that.

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
BetterRed is offline   Reply With Quote
Old 04-10-2017, 07:58 PM   #5
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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!).
mfm-ca is offline   Reply With Quote
Advert
Old 04-10-2017, 11:03 PM   #6
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: 43,914
Karma: 22669818
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
kovidgoyal is online now   Reply With Quote
Old 04-10-2017, 11:41 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: 20,611
Karma: 26954694
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
BR
BetterRed is offline   Reply With Quote
Old 04-11-2017, 12:43 AM   #8
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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.
mfm-ca is offline   Reply With Quote
Old 04-11-2017, 02:20 AM   #9
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: 20,611
Karma: 26954694
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.
BetterRed is offline   Reply With Quote
Old 04-11-2017, 10:18 AM   #10
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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.
mfm-ca is offline   Reply With Quote
Old 04-11-2017, 05:01 PM   #11
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: 20,611
Karma: 26954694
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:
  • For reasons unbeknownst to me, the output of an EPUB->RTF conversion always has the "Do not compress..." option checked, both before and after I apply one of my templates.
  • Whereas, the output of an EPUB->DOCX conversion never has the "Do not compress..." option checked, both before and even after I apply one of my templates.
I'm not sure I can help any further - maybe someone on one of the MS Word specialist (cough) forums, or at stackexchange, knows how to make the setting stick to all DOCX documents.

BR
BetterRed is offline   Reply With Quote
Old 04-11-2017, 06:29 PM   #12
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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.

Quote:
Originally Posted by BetterRed View Post
For reasons unbeknownst to me, the output of an EPUB->RTF conversion always has the "Do not compress..." option checked, both before and after I apply one of my templates.
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.
mfm-ca is offline   Reply With Quote
Old 04-11-2017, 08:25 PM   #13
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: 20,611
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by mfm-ca View Post
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.
Would setting the value in a macro that gets executed when a document is opened work for you.

Quote:
Originally Posted by mfm-ca View Post
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.
Something like that - I wonder what a .DOC does? But who cares, .DOC is a nightmare to convert from/to.

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
BetterRed is offline   Reply With Quote
Old 04-11-2017, 11:20 PM   #14
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: 43,914
Karma: 22669818
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)
kovidgoyal is online now   Reply With Quote
Old 04-12-2017, 10:46 AM   #15
mfm-ca
Enthusiast
mfm-ca began at the beginning.
 
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.
mfm-ca is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 10:01 AM.


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