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 01-22-2025, 09:19 AM   #1
Grandtoubab
Junior Member
Grandtoubab began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jan 2025
Device: calibre
Thumbs down Conversion to pdf with java in epub

Hello
I add an xhtml file called time.xhtml

Code:
 <?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
  <title>template</title>
  <link type="text/css" rel="stylesheet" href="stylesheet-tgp.css"/>
</head>



<body>
    <h1>Date et Heure</h1>
    <p id="datetime"></p>

    <!-- Include JavaScript at the end of the body -->
    <script src="META-INF/script.js"></script>
      

</body>
</html>

Then I add the java Script in META-INF/script.js


Code:
window.onload = function() {
    setInterval(function(){
        var date = new Date();
        var displayDate = date.toLocaleDateString();
        var displayTime = date.toLocaleTimeString();

        document.getElementById('datetime').innerHTML = displayDate + " " + displayTime;
    }, 1000); // 1000 milliseconds = 1 second
}
Then I add in the manifest

Code:
      <item href="META-INF/script.js" media-type="application/javascript" properties="scripted"/>
    <item id="id4" href="time.xhtml" media-type="application/xhtml+xml" properties="scripted"/>

All is runing perfect when I am in ebook-editor: Date and Time are displayed in the viewer.

But When I convert in pdf

Code:
ebook-convert testimp.epub testimp.pdf
1% Conversion de l’entrée en HTML…
InputFormatPlugin: EPUB Input running
on /home/guy/Documents/Livres/testimp.epub
Found HTML cover titlepage.xhtml
Parsing all content...
34% Exécution des transformations du livre numérique…
Merging user specified metadata...
Detecting structure...
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Trimming 'nav.xhtml' from manifest
Creating PDF Output...
67% Exécution de l'extension PDF Output
Traceback (most recent call last):
  File "runpy.py", line 198, in _run_module_as_main
  File "runpy.py", line 88, in _run_code
  File "site.py", line 47, in <module>
  File "site.py", line 43, in main
  File "calibre/ebooks/conversion/cli.py", line 422, in main
  File "calibre/ebooks/conversion/plumber.py", line 1294, in run
  File "calibre/ebooks/conversion/plugins/pdf_output.py", line 190, in convert
  File "calibre/ebooks/conversion/plugins/pdf_output.py", line 256, in convert_text
  File "calibre/ebooks/conversion/plugins/oeb_output.py", line 32, in convert
  File "calibre/ebooks/oeb/base.py", line 1971, in to_opf2
  File "calibre/ebooks/oeb/base.py", line 1278, in to_opf2
  File "calibre/ebooks/oeb/base.py", line 364, in element
  File "src/lxml/etree.pyx", line 3186, in lxml.etree.SubElement
  File "src/lxml/apihelpers.pxi", line 206, in lxml.etree._makeSubElement
  File "src/lxml/apihelpers.pxi", line 201, in lxml.etree._makeSubElement
  File "src/lxml/apihelpers.pxi", line 325, in lxml.etree._initNodeAttributes
  File "src/lxml/apihelpers.pxi", line 336, in lxml.etree._addAttributeToNode
  File "src/lxml/apihelpers.pxi", line 1528, in lxml.etree._utf8
TypeError: Argument must be bytes or unicode, got 'NoneType'

Is it impossible the date and time when the conversion occurs?
Grandtoubab is offline   Reply With Quote
Old 01-22-2025, 11:43 AM   #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,149
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yeah there are no guarantees about how arbitrary javascript will work when converting. Converting to PDF works by using chromiums print to pdf function.
kovidgoyal is offline   Reply With Quote
Advert
Old 01-22-2025, 12:45 PM   #3
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 13,651
Karma: 103503445
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
Don't add Javascript if wanting a PDF.

If I wanted anything special, I'd export the epub as docx, edit as odt in LO Writer (setting margins, headers, footers, page numbering etc) and export PDF from LO Writer.a
Quoth is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ePub->pdf conversion doesn't allow to add watermark with third-party pdf editor EbokJunkie Conversion 8 04-16-2023 08:38 PM
epub 2 PDF conversion with OCR in PDF possible? hobi2000 Conversion 2 03-25-2019 03:20 AM
Conversion PDF -> EPUB ? JPS Assistance 6 05-19-2016 03:34 PM
Converting PDF TO EPUB using Java Programming Ravi4484 Workshop 2 01-02-2015 03:32 PM
PDF to EPUB Conversion LuchoResto General Discussions 1 11-19-2010 04:54 PM


All times are GMT -4. The time now is 08:48 AM.


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