Another KDP tool

I like making books for Amazon’s Kindle Direct Publishing. Today I wanted to se if I could do a book filled with good comebacks. I searched the internet, paraphrased some with the help of an AI and I made some myself. Did not use my own favourite “Are you so great yourself then? So I wanted/needed a tool. Since I know how to make PDF files (KDP’s upload format #1) I decided to make such a tool. Then I made the book and then I decided to share the tool.

Here is an example of what it produces quote-test.pdf you can download the code here and you need processing from processing.org to run it.

import processing.pdf.*;

/* we need the pdf library */
PGraphicsPDF pdf;

/* 50 seems to be a good size if you want to get a pretty long quote in, but if you change the font, that will change */
int fontsize = 50;

/* variable needed so that we wont get a blank page at the end */

boolean isFirst = true;

void makeQuote(String quote)
{

  /* if this is  the first quote, don't make a new page in the pdf */
  if(!isFirst)
  {
    pdf.nextPage();
  }
  else
  {
   isFirst=false;
  }
 
  /* clearing the background to white */
  background(255);

  /* printing the quote on screen and in the pdf with a frame of whitespace around it */
  text(quote, 40, 40, width-80, height-80 ); 

 

}


void setup() 
{
  /* the size of the area will be set in pixels for processing, the pdf library will interpret it as points, so this is 6 inch by 9 inch size*/
  size(432, 649);  
  
  /* Loading a pretty font, you need to have this in the data directory */
  PFont font = createFont("Baloo2-Bold.ttf", fontsize);
  textFont(font,fontsize);

  /* initialisation of the pdf file */  
  pdf=  (PGraphicsPDF) beginRecord(PDF, "quote-test.pdf"); 
  /* if we don't tell the pdf library explicitly it will not include the font, this trick was hard to google */
  pdf.textFont(font);
  
  /* setting the text size alignment font and leading. Play around with these*/
  textAlign(LEFT, CENTER);
  fill(100);
  textSize(fontsize);
  textLeading(fontsize);    
   
  /* call all your quotes here, one by one, and they will be in the pdf document */ 
  /* for this example I took some from https://blog.hubspot.com/sales/famous-quotes remember to set a backspace before " marks and an \n if you want a new line*/
  makeQuote("\"The greatest glory in living lies not in never falling, but in rising every time we fall.\"\n-Nelson Mandela");

 makeQuote("\"The way to get started is to quit talking and begin doing.\"\n-Walt Disney");
 makeQuote("\"Life is what happens when you're busy making other plans.\"\n-John Lennon");
 makeQuote("\"The future belongs to those who believe in the beauty of their dreams.\" \n-Eleanor Roosevelt");
 makeQuote("\"Whoever is happy will make others happy too.\" \n-Anne Frank");

  
  /*stop recording to the pdf */
  endRecord();
  
  /*since we are don, let's exit*/
  exit();
}

void draw() {
}

Leave a Reply