code: private static void inlineImgNodes(final Document doc, final String basePath) {
          // handle null inputs
          if (doc == null) return;
  
          final String fixedBasePath = basePath == null ? "" : basePath;
  
          final List<Node> imageNodes = XMLUtilities.getChildNodes(doc.getDocumentElement(), "img");
          for (final Node node : imageNodes) {
              final NamedNodeMap attributes = node.getAttributes();
              final Node srcAttribute = attributes.getNamedItem("src");
              if (srcAttribute != null) {
                  final String src = srcAttribute.getTextContent();
                  final File srcFile = new File(fixedBasePath + "/" + src);
                  if (srcFile.exists()) {
                      final byte[] srcFileByteArray = FileUtilities.readFileContentsAsByteArray(srcFile);
                      if (srcFileByteArray != null) {
                          // get the file extension of the original image
                          final int extensionStringLocation = src.lastIndexOf(".");
  
                          // make sure we have an extension
                          if (extensionStringLocation != -1 && extensionStringLocation != src.length() - 1) {
                              final String extension = src.substring(extensionStringLocation + 1);
  
                              // encode the image
                              final byte[] srcFileEncodedByteArray = Base64.encodeBase64(srcFileByteArray);
                              final String srcFileEncodedString = new String(srcFileEncodedByteArray);
  
                              final Node parent = node.getParentNode();
                              if (parent != null) {
                                  final Element newImgNode = doc.createElement("img");
                                  newImgNode.setAttribute("src", "data:image/" + extension + ";base64," + srcFileEncodedString);
  
                                  parent.replaceChild(newImgNode, node);
                              }
                          }
                      }
                  }
              }
          }
      }
docs: Finds any reference to an external images and replaces them with inline
  base64 data
  
  @param doc      The document that holds the XHTML
  @param basePath The base path where the images can be found