![]() |
#1 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 63058
Join Date: Feb 2012
Device: Kobo Aura One
|
Adding image to notes
Hello,
I'm creating a plugin that grabs author information and adds it to notes. I've looked through the API documentation and thought I had everything figured out, but I'm running into a wall. I'm creating an html table that contains various author info. For the picture, I'm using pythons requests module to get image data from a url and then using Calibre's add_notes_resource function to create the resource. I'm using the hash to add an <img> tag to the table. When the note is created, the img source is empty. As a test, I had my code print out the final html block that is imported using the import_note function. This block has the img source, and if I manually take this html block and add it to the note as html source, the image shows up, so I know the resource is being created correctly. I'm just unsure why the src part of the image tag is being deleted when being imported as a note. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,176
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Use import_note() to import your html file. Embed the images using data: URLs in the html
Last edited by kovidgoyal; 12-09-2023 at 06:26 AM. |
![]() |
![]() |
![]() |
#3 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 63058
Join Date: Feb 2012
Device: Kobo Aura One
|
Ooof, didn't even think about using data: URLs and was banging my head trying to get the notes resources working. Tested data: URLs and everything is great.
|
![]() |
![]() |
![]() |
#4 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 63058
Join Date: Feb 2012
Device: Kobo Aura One
|
One quick follow-up question to this. Is there a function to completely delete a note? I don't even see a way to do it through the Calibre interface? For now, I'm just replacing the note with an empty note, but that still leaves the author names in the "Book Details" panel as having notes (i.e. they have the pencil icon next to the name).
|
![]() |
![]() |
![]() |
#5 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,616
Karma: 29710338
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
I got caught by stray white space, now I Ctrl+A in HTML Tab, press Del, then press Ctrl+Numpad-Del. Pencil gone. BR |
|
![]() |
![]() |
![]() |
#6 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I will look at adding "Delete" to the note context menu in book details. EDIT: change in calibre source. Last edited by chaley; 12-10-2023 at 06:44 AM. Reason: Change to add delete note to the context menu is in source |
|
![]() |
![]() |
![]() |
#7 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 63058
Join Date: Feb 2012
Device: Kobo Aura One
|
Just to clarify, if I delete the entire note from the HTML tab, it does remove the pencil. If I perform a import_note() where the data to import is empty, it removes the content, but does not remove the pencil.
I just tested, and on those where I have cleared the note using the import_note() function, I can open the note, go to HTML and click OK (without changing anything) and the pencil goes away, so there's definitely nothing in there. |
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,176
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Importing an empty note does not delete the note it just sets it to an empty document. Use set_notes_for() with an empty document to delete the note instead. importing is meant for importing actual notes.
|
![]() |
![]() |
![]() |
#9 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
gui.do_field_item_value_changed() |
|
![]() |
![]() |
![]() |
#10 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,176
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
And yes you have ot refresh the gui after deleting as charles points out.
|
![]() |
![]() |
![]() |
#11 |
Enthusiast
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 32
Karma: 63058
Join Date: Feb 2012
Device: Kobo Aura One
|
Thank you everyone. This got everything sorted.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
adding notes to books while reading | sabri | Calibre | 4 | 12-06-2018 09:57 PM |
Highlighting and Adding Notes in Caliber | light1 | Calibre | 0 | 08-25-2013 02:50 PM |
Restrictions with adding notes to books | lockheed | Amazon Kindle | 4 | 10-12-2012 11:00 AM |
Adding notes | 20LEgend | Amazon Kindle | 5 | 02-10-2011 03:56 PM |
Reader for adding notes? | kingofaces | Which one should I buy? | 1 | 11-30-2010 12:15 PM |