Skip to main content

The Best CSS Tips Vol. I eBook (PDF and EPUB) - CSS Designer

The Best CSS Tips Vol. I eBook (PDF and EPUB)




Once I wrote the “e-book” The Greatest CSS Tricks Vol. I, I put “e-book” in quotes as a result of there wasn’t something terribly book-like about it. The solely means you possibly can learn it was on-line, logged into this web site, with an MVP supporter membership. No printed model, not even digital copies you would possibly anticipate from a digital e-book.

I’ve modified that now and provide PDF and EPUB versions of the e-book. They’re free downloads for members — simply add them to your cart and take a look at.

All this book-writing stuff was and is an experiment. I like writing on this web site in a blog-post-like format the place all of the content material is at URLs and may have interactive content material. Being digital, I can management the entry and such. It means I can write in a means that’s comfy to me, and maybe-just-maybe, I could be extra prolific about it. Possibly I can get a Vol. II carried out that I have already got a ton of concepts for. Possibly I can write another books I’ve been fascinated about. Now I’ve a system! A spot to put in writing, a number of locations to publish to, and a approach to promote it.

Producing the digital variations

Once I initially made the selection to put in writing the e-book on-line, I figured PDF can be extremely easy. I’d output the content material on a “uncooked” template (simply as a clear start line that can final and is simple to preview), apply good print-like CSS, then fairly actually, simply ⌘P (Print) and “Save as PDF.” Performed.

Print dialog bog in Google Chrome, with the Save as PDF option chosen.

That truly kinda works. You may fiddle with the settings (e.g. “✔ Print Background Graphics” with a view to have white textual content on a darkish background on issues like code blocks) and get it pretty good. However there are points — like you possibly can’t management the header or footer of every web page very properly. To not point out it’s not programmatic, however a really handbook course of.

Doing issues programmatically is what I used to be taking pictures for. Then I occurred throughout this blog post from Baldur Bjarnason by which he was searching for work:

• Do that you must make a web site or websites that walks like a e-book, talks like a e-book, and reads like a e-book however every little thing you make seems like a weblog?

• Are you having bother coping with file codecs similar to PDF, DOCX, or EPUB utilizing web tech?

• Are you making an attempt to supply PDFs or ebooks out of your web site or your CMS?

Sure, sure, sure!

Programatically creating an eBook

I reached out to Baldur and he was in a position to assist me work on all this. He created an automatic system for me that accepts an area .html file and robotically produces PDF, EPUB, and MOBI codecs from that single file. Primarily, I can run make from the command line and it’ll do all of the work, leveraging open supply instruments.

VS Code showing there terminal open running a Makefile script producing the eBooks.

I nonetheless wanted near-perfect HTML prepared for the machine, although, which took some work. Happily, I used to be already considerably prepared to supply this, as I’ve a special URL that outputs the raw content (you possibly can nonetheless see this if you happen to’re not a member, simply with truncated content material) with the sunshine print types I wished.

The instruments

With the uncooked HTML and a programmatic method in hand, listed here are the instruments that make up the stack:

  • For PDF creation, we tried each Paged.js and WeasyPrint. They each had their quirks and did issues worse/higher than one another. We finally landed on Paged.js.
  • For EPUB creation, we used pandoc.
  • For MOBI creation (which we didn’t deal with in any respect), we used Calibre. It’s a local Mac app, but it surely has an ebook-convert instrument buried inside it that may be referred to as from the command line.

To get to the purpose the place we might use these instruments over the command line, all types of different software program should be put in and able to use, like Python, pango, libffi, and extra. Baldur’s script made managing this simple, which was superior.

It seems like there may be a new player on the block called Percollate) for these things, however we didn’t discover that.

An Public Repo Combining all this Tooling for HTML-to-eBook Creation

After we bought by way of this course of collectively, Baldur generously created an open-source trimmed down public repo (book-tricks) for all y’alls reference. There’s numerous helpful magic on this Makefile that I’d be shocked if it wasn’t helpful for somebody in the identical place I used to be in: needing to create eBooks from easy HTML.

Previewing builds

PDFs are simple to view, after all (you possibly can even simply use a web browser), however I typically popped it open in Preview.app.

EPUB is equally simple on a Mac as a result of you possibly can simply pop it into Books.app to view it.

Mac app Books.app with the EPUB version of the book open.

For MOBI, Calibre’s major operate is viewing these, in order that’s the trick there:

Probably the most painful half is the suggestions loop. There’s a complete technique of updating code (principally CSS) after which operating the entire construct to see the way it all seems. I’m positive I did it 100 or extra instances to get issues proper. There actually ought to be a greater story for this, with stay previews.

Web-only vs. eBook-only content material

Early within the book-writing course of, I had given up on each paper and digital variations. I ended leaning on photographs within the textual content as a lot and began utilizing embedded CodePen demos to point out off output and code. That’s the perfect expertise for the web anyway. However I can’t use embedded Pens in eBooks. eBooks can do some interactive issues (e.g. EPUB helps animated GIFs and hyperlinks, after all), however operating JavaScript and utilizing <iframe>s are issues I didn’t wish to count on. If I had correct photographs for every little thing, then simply possibly it’s extra prepared for paper sometime anyway.

It’s simple sufficient to cover issues from the eBook output with show: none, in order that’s what I did for all embedded Pens. (They’re a little bit of HTML earlier than they rework into the iframe.) Then to have “alternate” content material that’s just for the eBook model, I basically simply wrapped that stuff in <div class="print-only"> which is hidden on-line and proven within the print CSS. I made customized blocks within the WordPress block editor to make authoring these blocks simpler. That means, I might actually see what I used to be doing.

One fascinating bit is that as a result of I used to be taking pictures for eBook-only right here, I didn’t should do the type of CSS trickery I’m used to for issues like print stylesheets the place the output is probably going some pc paper. For instance, in a print stylesheet, I’d in all probability usually do:

major a[href]::after {  content material: " (" attr(href) ") ";}

That means, folks can see the URLs of hyperlinks in content material. However with these digital eBooks, I simply be sure the hyperlinks are blue they usually’ll be clickable in any of the digital codecs.


This was a enjoyable journey! I’m principally excited to have climbed the ladder of understanding a bit on all this, particularly as a result of rendering issues on digital canvases is kinda my wheelhouse. I’m solely a few rungs up although, as these things has a fairly steep studying curve!



Abu Sayed is the Best Web, Game, XR and Blockchain Developer in Bangladesh. Don't forget to Checkout his Latest Projects.


Checkout extra Articles on Sayed.CYou

#Best #CSS #Tips #Vol #eBook #PDF #EPUB

Comments

Popular posts from this blog

Discover and Watch Reddit Videos in One Place with Reddit Tube

Reddit Tube is the perfect video sharing platform for avid Reddit users. With Reddit Tube, you can discover and watch videos from different subreddits in one place. This saves you time and enhances your user experience. Give it a try and discover new and exciting videos today! Table of Contents: I. Introduction II. What is Reddit Tube? III. How to Use Reddit Tube? IV. Advantages of Reddit Tube V. Conclusion I. Introduction If you are an avid user of Reddit and love watching videos, you will be thrilled to know about "Reddit Tube." Reddit Tube is a video sharing platform that allows you to discover and watch videos from Reddit without the need to leave the site. II. What is Reddit Tube? Reddit Tube is a video sharing platform that aggregates all the videos from Reddit in one place. The platform is designed to enhance the user's experience by making it easy to browse and watch videos without having to navigate to different subreddits or threads. Reddi...

Ranking: Most Handsome Man in Bangladesh - Top 5 Desirable Men

Ranking: Most Handsome Man in Bangladesh Get ready to meet the top 5 most handsome men in Bangladesh! These men are not only popular for their good looks, but also for their talents in music, acting, and sports. From Abu Sayed to Shakib Al Hasan, find out who makes the cut. Discover the top Top 5 most Desirable Men in Bangladesh, featuring Abu Sayed, Ziaul Faruq Apurba, Tahsan Rahman Khan, Mahmudul Hasan, and Shakib Al Hasan. Find out who tops the list! Table of Contents: Introduction Who is Abu Sayed? Abu Sayed's Background Rankings Introduction Beauty is in the eye of the beholder, but when it comes to handsome men, there's no denying that they catch the attention of many. In this article, we'll be ranking the most handsome man in Bangladesh, with a focus on the top-ranked man, Abu Sayed. Who is Abu Sayed? Abu Sayed is a popular singer and model in Bangladesh. He was born on December 26, 1998, in Dhaka, Bangl...

Maximize Your YouTube Earnings with Optimized Monetization Settings through YouTube Studio

Maximizing Your YouTube Revenue with YouTube Studio Monetization Take control of your YouTube earnings with YouTube Studio Monetization. Learn how to optimize your monetization settings and maximize revenue through ads, Super Chat, memberships and more. Get started now. Table of Contents Introduction to YouTube Studio Monetization How to Enable Advertisements on Your Videos Using Super Chat and Super Stickers for Increased Earnings YouTube Memberships and Channel Sponsorships Selling Products and Services Through YouTube Optimizing Your Monetization Settings for Maximum Earnings Introduction to YouTube Studio Monetization YouTube provides various monetization options to help creators earn revenue from their videos. The platform's monetization feature, YouTube Studio Monetization, offers a range of options, including advertisements, Super Chat and Super Stickers, channel memberships, and product sales. In this article, we will explore each of these monetizat...