Tuesday 9 September 2014

Unable to sanitize epub - Have a brick wall handy

Because writers need to make sure their self-published book is available across all possible channels, I've spent most of this morning trying to publish mine on Google Play. 

And because this was a less than easy task, I've spent most of the afternoon venting my frustration into a long, unhelpful and rather dull blog tirade.

Once finished I felt better about things... Then I realised that few people would care and rightly enough. 

So, for those of you having problems uploading your file onto Google Play and especially anyone receiving the message Error: Unable to sanitize epub, here is a more concise and a lot less cynical post about how I got round it. There are probably easier methods but I couldn't find any so this is just my attempt. Feel free to suggest different approaches.

Unlike Amazon and Smashwords, Google require you to upload a ready formatted eBook file in epub format, rather than use a text or html file to create the ebook file on your behalf. So using the HTML file I had uploaded to Amazon, I used Calibre to create the epub. 

Unfortunately, though the file seemed OK, was readable on a Kindle and was based on a file that both Smashwords and Amazon had accepted, Google didn't like it and merely gave the message Error: Unable to sanitize epub

I assume there is a setting within Calibre that was incorrect when it created the file, I'm just not sure it was. Sadly the Google error message is less than helpful and their FAQ merely states you should go away and validate the file without offering further advice.

Epub files are relatively complicated things for the unwary, full of not just your written content but a whole host of background HTML Wizardy. So to say "Go away and validate your file" without even advising whether its the content that needs formatting or the shell of the epub file itself, is like telling someone stuck in quicksand to go away and study the properties of non-Newtonian Fluids. Yeah... cheers. couldn't you just throw me a rope?

So, to get round this I tried to see if the epub that Smashwords had created from my original Word Doc would be any better. But before I could do this I had to remove the Smashwords Licence Statement that they request you add before selling through them. 

I didn't want to re-format this file into an editable file type because I would probably end up with the same error when I re-formatted it back to epub in Calibre, so I needed to remove the references to Smashwords directly in the epub file itself. Here are the steps I took:

  • Download Epub file from Smashwords (Authors are allowed full access to all the file types Smashwords create from the original file uploaded)
  • Add this file to your Calibre library
  • Right click on the book and select either "Tweak" or "Edit" Book.
  • Select "Explode Book" which pulls all the elements of the book apart and shows you the separate files in HTML format.
  • From the list of files you are shown you need to select the HTML file where the Smashwords Licence Statement is stored. The files should be in "element" order (Title, Copyright page, Contents, Chapter 1, Chapter 2 etc...) so assuming the first element is the title page (not the front cover) the second element should be the copyright page with the licence statement, so select that HTML file. 
  • Open this file with a text editor like Notepad
  • Welcome to the wacky world of HTML. hopefully amongst the code you should be able to work out if this is the correct page. If you know what you're doing, go ahead and delete the Smashwords statement. If you don't, you need to be very careful not to delete or change the wrong thing otherwise you'll need to start again from the top. Not a dissaster, just annoying. To limit any mistakes it's probably easier to hit "Ctrl F" to open the "find" box and search for all references to "Smashwords". One at a time you can then replace that word with "Google" or if you feel confident you can delete the whole section without damaging the HTML code.
  • Once changed, save and close the editor and return to Calibre
  • Underneath "Explode Book" there should be the option to "Rebuild book". 
  • Now you should be able to read the book in Calibre with the new edits. 
  • Export this version of the book from Calibre and upload to Google.
Don't worry if you do mess up the HTML, as long as you don't hit "save" you can always close and then re-open the HTML file and try again. If you do accidentally save a mistake just remove and then re-add the original SW epub to Calibre and start again.

As I mentioned at the top, there are probably easier methods than this, but I couldn't think of any. I only took this route because the epub I was creating in Calibre originally was rejected and the usable epub I downloaded from SW needed to be edited before it could be uploaded to Google. Let me know if you have an easier solution or if you know why the first epub i created was rejected.



No comments:

Post a Comment