Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 06:09 PM   #1
neo1
Junior Member
neo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texan
 
Posts: 9
Karma: 18470
Join Date: Jun 2026
Device: none
calibre viewer css file?

Calibre -> Preferences -> Styles

leads to the viewer custom css file configuration. Using this
interface to edit the css file is a huge pain point. It is MUCH easier
to use a proper file editor on the local system. I can not
find a file one can edit on the local system that would have the same
effect. Am I missing something?

The file viewer-webengine.json in CALIBRE_CONFIG_DIRECTORY stores this
css style sheet inside the user_stylesheet variable. Changing the
style sheet there has the desired effect. The below bash script
(Linux) automates this task. It's basically a one liner. You
edit a local file in your favorite editor then inject it into
viewer-webengine.json.

NOTE: calibre viewer should be closed doing this, or it doesn't work.

#!/bin/bash
###
# set these accordingly
MYFILE=$HOME/calibre.css
CALIBRE_CONFIG_DIRECTORY=$HOME/.config/calibre
###

config_file=$CALIBRE_CONFIG_DIRECTORY/viewer-webengine.json
tmp=$(mktemp) # create a temporary file
jq --arg val "$(<"$MYFILE")" '."session_data"."user_stylesheet" = $val' "$config_file" >"$tmp" && mv "$tmp" "$config_file"
neo1 is offline   Reply With Quote
Old Yesterday, 11:00 PM   #2
neo1
Junior Member
neo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texanneo1 might easily be mistaken for a Texan
 
Posts: 9
Karma: 18470
Join Date: Jun 2026
Device: none
line cut off

The last two lines in my previous post, is really one line that got
cut off. So much for trying to post code.

Here's a link to a proper write up that containing a link to the file with the
code along with an explanation.
link

Here's a link to the shell script file
file
neo1 is offline   Reply With Quote
Advert
Old Yesterday, 11:38 PM   #3
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 55,248
Karma: 182532776
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Code should be wrapped in [CODE][/CODE] (the # tool)...

Code:
#!/bin/sh
###
# set these accordingly
CSS_FILE=$HOME/calibre.css
CALIBRE_CONFIG_DIRECTORY=$HOME/.config/calibre
###

config_file=$CALIBRE_CONFIG_DIRECTORY/viewer-webengine.json
tmp=$(mktemp) # create a temporary file
jq --arg val "$(cat "$CSS_FILE")" '."session_data"."user_stylesheet" = $val' "$config_file" >"$tmp" && mv "$tmp" "$config_file"
Code:
--arg val "$(cat "$CSS_FILE")" : sets the variable val to the contents of $CSS_FILE

'."session_data"."user_stylesheet" = $val' : jq program to run. It assigns the variable "session_data"."user_stylesheet" to the value of the variable val, i.e. the contents of $CSS_FILE

"$config_file" : is the source file

> "$tmp" : send the output of jq to a temporary file

&& mv "$tmp" "$config_file" : and if all goes well replace the original with the temporary file

Last edited by DNSB; Yesterday at 11:44 PM.
DNSB is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom CSS Stylesheets for Calibre's Viewer Ralob Viewer 396 06-26-2026 09:30 AM
Customize viewer css. pygments.css not found drglenn Viewer 2 12-18-2020 04:52 PM
Css for Calibre viewer background-color Cjammi Calibre 5 03-10-2017 12:09 PM
Calibre: eBook Viewer - CSS Bug navjot001 Library Management 1 03-25-2014 08:55 AM
# user css for viewer.py/ ebook-viewer/ prs-650 tscamera Calibre 0 01-02-2011 06:28 PM


All times are GMT -4. The time now is 02:24 AM.


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