├── .gitignore
├── LICENSE
├── README.md
├── ScannedImages-to-PDF.py
├── ml.txt
├── myfont
├── 0.png
├── 1.png
├── 2.png
├── 3.png
├── 4.png
├── 5.png
├── 6.png
├── 7.png
├── 8.png
├── 9.png
├── a.png
├── aupper.png
├── b.png
├── bg.png
├── braketcl.png
├── braketop.png
├── bupper.png
├── c.png
├── comma.png
├── cupper.png
├── d.png
├── dupper.png
├── e.png
├── eupper.png
├── exclamation.png
├── f.png
├── fullstop.png
├── fupper.png
├── g.png
├── gupper.png
├── h.png
├── hiphen.png
├── hupper.png
├── i.png
├── iupper.png
├── j.png
├── jupper.png
├── k.png
├── kupper.png
├── l.png
├── lupper.png
├── m.png
├── mupper.png
├── n.png
├── nupper.png
├── o.png
├── oupper.png
├── p.png
├── pupper.png
├── q.png
├── question.png
├── qupper.png
├── r.png
├── rupper.png
├── s.png
├── space.png
├── supper.png
├── t.png
├── tupper.png
├── u.png
├── uupper.png
├── v.png
├── vupper.png
├── w.png
├── wupper.png
├── x.png
├── xupper.png
├── y.png
├── yupper.png
├── z.png
└── zupper.png
├── requirements.txt
└── txttohandwriting.py
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode
2 | final_output.pdf
3 | *.png
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2020 Sharanya Mukherjee
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
Text to Handwriting converter
3 | Convert text files into handwritten PDFs
4 |
5 |
6 |
7 | ## Functionalities
8 | - [X] Convert a text document (.txt file) into a PDF file with the text content handwritten
9 |
10 | ## Pre-requisites:
11 | - [X] python 3.5 or 3.6
12 | - [X] [Install Tesseract: an open source text recognition (OCR) Engine](https://github.com/tesseract-ocr/tessdoc/blob/master/Home.md)
13 | - [X] dependencies from requirements.txt
14 |
15 | ```
16 | $ pip install requirements.txt
17 | ```
18 |
19 | ## Installing required python dependencies
20 | - Clone this repository onto your system
21 | ```bash
22 | git clone https://github.com/sharanya02/Text-file-to-handwritten-pdf-file
23 | ```
24 | - Then, create a virtual environment and install the packages from requirements.txt.
25 | ```bash
26 | pip install virtualenv
27 | virtualenv env
28 | source env/bin/activate
29 | pip install -r requirements.txt
30 | ```
31 | ## Directions to run
32 | - Run the following command in the project directory:
33 | ```
34 | python txttohandwriting.py
35 | ```
36 |
37 |
--------------------------------------------------------------------------------
/ScannedImages-to-PDF.py:
--------------------------------------------------------------------------------
1 | # Usage
2 | # python ScannedImages-to-PDF.py -i image_path
3 |
4 | from PIL import Image
5 | import pytesseract
6 | import argparse
7 | import cv2
8 | import os
9 |
10 | # construct the argument parse and parse the arguments
11 | ap = argparse.ArgumentParser()
12 | ap.add_argument("-i",
13 | "--image",
14 | required=True,
15 | help="path to input image to be OCR'd")
16 | ap.add_argument("-p",
17 | "--preprocess",
18 | type=str,
19 | default="thresh",
20 | help="type of preprocessing to be done")
21 | args = vars(ap.parse_args())
22 |
23 | # load the example image and convert it to grayscale
24 | image = cv2.imread(args["image"])
25 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
26 |
27 | #cv2.imshow("Image", gray)
28 |
29 | # check to see if we should apply thresholding to preprocess the
30 | # image
31 | if args["preprocess"] == "thresh":
32 | gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
33 |
34 | # make a check to see if median blurring should be done to remove
35 | # noise
36 | elif args["preprocess"] == "blur":
37 | gray = cv2.medianBlur(gray, 3)
38 |
39 | # write the grayscale image to disk as a temporary file so we can
40 | # apply OCR to it
41 | filename = "{}.png".format(os.getpid())
42 | cv2.imwrite(filename, gray)
43 |
44 | # load the image as a PIL/Pillow image, apply OCR, and then delete
45 | # the temporary file
46 | pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
47 | text = pytesseract.image_to_string(Image.open(filename))
48 | os.remove(filename)
49 | print(text.encode("utf-8"))
50 |
51 | file = open("testfile.txt", "w+")
52 |
53 | file.write(text)
54 | file.close()
55 |
56 | # show the output images
57 | # cv2.imshow("Image", image)
58 | #cv2.imshow("Output", gray)
59 | cv2.waitKey(0)
60 | print("------------------- processed OCR -------------------")
61 | BG = Image.open("myfont\\bg.png")
62 | sizeOfSheet = BG.width
63 | gap, _ = 0, 0
64 | allowedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,.-?!() 1234567890'
65 |
66 |
67 | def writee(char):
68 | global gap, _
69 | if char == '\n':
70 | pass
71 | else:
72 | char.lower()
73 | cases = Image.open("myfont/%s.png" % char)
74 | BG.paste(cases, (gap, _))
75 | size = cases.width
76 | gap += size
77 | del cases
78 |
79 |
80 | def letterwrite(word):
81 | global gap, _
82 | if gap > sizeOfSheet - 95 * (len(word)):
83 | gap = 0
84 | _ += 200
85 | for letter in word:
86 | if letter in allowedChars:
87 | if letter.islower():
88 | pass
89 | elif letter.isupper():
90 | letter = letter.lower()
91 | letter += 'upper'
92 | elif letter == '.':
93 | letter = "fullstop"
94 | elif letter == '!':
95 | letter = 'exclamation'
96 | elif letter == '?':
97 | letter = 'question'
98 | elif letter == ',':
99 | letter = 'comma'
100 | elif letter == '(':
101 | letter = 'braketop'
102 | elif letter == ')':
103 | letter = 'braketclose'
104 | elif letter == '-':
105 | letter = 'hiphen'
106 | writee(letter)
107 |
108 |
109 | def worddd(Input):
110 | wordlist = Input.split(' ')
111 | for i in wordlist:
112 | letterwrite(i)
113 | writee('space')
114 |
115 |
116 | if __name__ == '__main__':
117 | try:
118 | with open('testfile.txt', 'r') as file:
119 | data = file.read().replace('\n', '')
120 | l = len(data)
121 | nn = len(data) // 600
122 | chunks, chunk_size = len(data), len(data) // (nn + 1)
123 | p = [data[i:i + chunk_size] for i in range(0, chunks, chunk_size)]
124 |
125 | for i in range(0, len(p)):
126 | worddd(p[i])
127 | writee('\n')
128 | BG.save('myfont/%doutt.png' % i)
129 | BG1 = Image.open("myfont/bg.png")
130 | BG = BG1
131 | gap = 0
132 | _ = 0
133 | except ValueError as E:
134 | print("{}\nTry again".format(E))
135 |
136 | #for conversion of img to pdf
137 | from fpdf import FPDF
138 | from PIL import Image
139 | print("------------------- Converting to PDF -------------------")
140 | imagelist = []
141 | for i in range(0, len(p)):
142 | imagelist.append('myfont/%doutt.png' % i)
143 | cover = Image.open(imagelist[0])
144 | width, height = cover.size
145 | pdf = FPDF(unit="pt", format=[width, height])
146 | for i in range(0, len(imagelist)):
147 | pdf.add_page()
148 | pdf.image(imagelist[i], 0, 0)
149 | pdf.output("output.pdf", "F")
150 |
--------------------------------------------------------------------------------
/ml.txt:
--------------------------------------------------------------------------------
1 | What is Machine Learning?
2 |
3 | Machine learning is an application of artificial intelligence (AI) that provides systems the ability to automatically learn and improve from experience without being explicitly programmed. Machine learning focuses on the development of computer programs that can access data and use it learn for themselves.
4 |
5 | The process of learning begins with observations or data, such as examples, direct experience, or instruction, in order to look for patterns in data and make better decisions in the future based on the examples that we provide. The primary aim is to allow the computers learn automatically without human intervention or assistance and adjust actions accordingly.
6 |
7 | But, using the classic algorithms of machine learning, text is considered as a sequence of keywords; instead, an approach based on semantic analysis mimics the human ability to understand the meaning of a text.
8 |
9 | Machine learning algorithms are often categorized as supervised or unsupervised.
10 |
11 | Supervised machine learning algorithms can apply what has been learned in the past to new data using labeled examples to predict future events. Starting from the analysis of a known training dataset, the learning algorithm produces an inferred function to make predictions about the output values. The system is able to provide targets for any new input after sufficient training. The learning algorithm can also compare its output with the correct, intended output and find errors in order to modify the model accordingly.
12 |
13 | In contrast, unsupervised machine learning algorithms are used when the information used to train is neither classified nor labeled. Unsupervised learning studies how systems can infer a function to describe a hidden structure from unlabeled data. The system doesn’t figure out the right output, but it explores the data and can draw inferences from datasets to describe hidden structures from unlabeled data.
14 |
15 | Semi-supervised machine learning algorithms fall somewhere in between supervised and unsupervised learning, since they use both labeled and unlabeled data for training – typically a small amount of labeled data and a large amount of unlabeled data. The systems that use this method are able to considerably improve learning accuracy. Usually, semi-supervised learning is chosen when the acquired labeled data requires skilled and relevant resources in order to train it / learn from it. Otherwise, acquiring unlabeled data generally doesn’t require additional resources.
16 |
17 | Reinforcement machine learning algorithms is a learning method that interacts with its environment by producing actions and discovers errors or rewards. Trial and error search and delayed reward are the most relevant characteristics of reinforcement learning. This method allows machines and software agents to automatically determine the ideal behavior within a specific context in order to maximize its performance. Simple reward feedback is required for the agent to learn which action is best; this is known as the reinforcement signal.
--------------------------------------------------------------------------------
/myfont/0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/0.png
--------------------------------------------------------------------------------
/myfont/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/1.png
--------------------------------------------------------------------------------
/myfont/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/2.png
--------------------------------------------------------------------------------
/myfont/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/3.png
--------------------------------------------------------------------------------
/myfont/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/4.png
--------------------------------------------------------------------------------
/myfont/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/5.png
--------------------------------------------------------------------------------
/myfont/6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/6.png
--------------------------------------------------------------------------------
/myfont/7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/7.png
--------------------------------------------------------------------------------
/myfont/8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/8.png
--------------------------------------------------------------------------------
/myfont/9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/9.png
--------------------------------------------------------------------------------
/myfont/a.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/a.png
--------------------------------------------------------------------------------
/myfont/aupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/aupper.png
--------------------------------------------------------------------------------
/myfont/b.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/b.png
--------------------------------------------------------------------------------
/myfont/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/bg.png
--------------------------------------------------------------------------------
/myfont/braketcl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/braketcl.png
--------------------------------------------------------------------------------
/myfont/braketop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/braketop.png
--------------------------------------------------------------------------------
/myfont/bupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/bupper.png
--------------------------------------------------------------------------------
/myfont/c.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/c.png
--------------------------------------------------------------------------------
/myfont/comma.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/comma.png
--------------------------------------------------------------------------------
/myfont/cupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/cupper.png
--------------------------------------------------------------------------------
/myfont/d.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/d.png
--------------------------------------------------------------------------------
/myfont/dupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/dupper.png
--------------------------------------------------------------------------------
/myfont/e.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/e.png
--------------------------------------------------------------------------------
/myfont/eupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/eupper.png
--------------------------------------------------------------------------------
/myfont/exclamation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/exclamation.png
--------------------------------------------------------------------------------
/myfont/f.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/f.png
--------------------------------------------------------------------------------
/myfont/fullstop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/fullstop.png
--------------------------------------------------------------------------------
/myfont/fupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/fupper.png
--------------------------------------------------------------------------------
/myfont/g.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/g.png
--------------------------------------------------------------------------------
/myfont/gupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/gupper.png
--------------------------------------------------------------------------------
/myfont/h.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/h.png
--------------------------------------------------------------------------------
/myfont/hiphen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/hiphen.png
--------------------------------------------------------------------------------
/myfont/hupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/hupper.png
--------------------------------------------------------------------------------
/myfont/i.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/i.png
--------------------------------------------------------------------------------
/myfont/iupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/iupper.png
--------------------------------------------------------------------------------
/myfont/j.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/j.png
--------------------------------------------------------------------------------
/myfont/jupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/jupper.png
--------------------------------------------------------------------------------
/myfont/k.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/k.png
--------------------------------------------------------------------------------
/myfont/kupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/kupper.png
--------------------------------------------------------------------------------
/myfont/l.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/l.png
--------------------------------------------------------------------------------
/myfont/lupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/lupper.png
--------------------------------------------------------------------------------
/myfont/m.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/m.png
--------------------------------------------------------------------------------
/myfont/mupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/mupper.png
--------------------------------------------------------------------------------
/myfont/n.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/n.png
--------------------------------------------------------------------------------
/myfont/nupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/nupper.png
--------------------------------------------------------------------------------
/myfont/o.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/o.png
--------------------------------------------------------------------------------
/myfont/oupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/oupper.png
--------------------------------------------------------------------------------
/myfont/p.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/p.png
--------------------------------------------------------------------------------
/myfont/pupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/pupper.png
--------------------------------------------------------------------------------
/myfont/q.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/q.png
--------------------------------------------------------------------------------
/myfont/question.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/question.png
--------------------------------------------------------------------------------
/myfont/qupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/qupper.png
--------------------------------------------------------------------------------
/myfont/r.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/r.png
--------------------------------------------------------------------------------
/myfont/rupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/rupper.png
--------------------------------------------------------------------------------
/myfont/s.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/s.png
--------------------------------------------------------------------------------
/myfont/space.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/space.png
--------------------------------------------------------------------------------
/myfont/supper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/supper.png
--------------------------------------------------------------------------------
/myfont/t.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/t.png
--------------------------------------------------------------------------------
/myfont/tupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/tupper.png
--------------------------------------------------------------------------------
/myfont/u.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/u.png
--------------------------------------------------------------------------------
/myfont/uupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/uupper.png
--------------------------------------------------------------------------------
/myfont/v.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/v.png
--------------------------------------------------------------------------------
/myfont/vupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/vupper.png
--------------------------------------------------------------------------------
/myfont/w.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/w.png
--------------------------------------------------------------------------------
/myfont/wupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/wupper.png
--------------------------------------------------------------------------------
/myfont/x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/x.png
--------------------------------------------------------------------------------
/myfont/xupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/xupper.png
--------------------------------------------------------------------------------
/myfont/y.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/y.png
--------------------------------------------------------------------------------
/myfont/yupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/yupper.png
--------------------------------------------------------------------------------
/myfont/z.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/z.png
--------------------------------------------------------------------------------
/myfont/zupper.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/freAK14/Text-file-to-handwritten-pdf-file/4ec30191019f4918ffe139686eb7324334911baa/myfont/zupper.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | fpdf==1.7.2
2 | numpy==1.19.0
3 | opencv-python==4.2.0.34
4 | Pillow==7.1.2
5 | pytesseract==0.3.4
6 |
--------------------------------------------------------------------------------
/txttohandwriting.py:
--------------------------------------------------------------------------------
1 | from PIL import Image
2 | from fpdf import FPDF
3 | from PIL import Image
4 | import os
5 | BG = Image.open("myfont/bg.png")
6 | sizeOfSheet = BG.width
7 | gap, _ = 0, 0
8 | allowedChars = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM,.-?!() 1234567890'
9 |
10 |
11 | def writee(char):
12 | global gap, _
13 | if char == '\n':
14 | pass
15 | else:
16 | char.lower()
17 | cases = Image.open("myfont/%s.png" % char)
18 | BG.paste(cases, (gap, _))
19 | size = cases.width
20 | gap += size
21 | del cases
22 |
23 |
24 | def letterwrite(word):
25 | global gap, _
26 | if gap > sizeOfSheet - 95 * (len(word)):
27 | gap = 0
28 | _ += 200
29 | for letter in word:
30 | if letter in allowedChars:
31 | if letter.islower():
32 | pass
33 | elif letter.isupper():
34 | letter = letter.lower()
35 | letter += 'upper'
36 | elif letter == '.':
37 | letter = "fullstop"
38 | elif letter == '!':
39 | letter = 'exclamation'
40 | elif letter == '?':
41 | letter = 'question'
42 | elif letter == ',':
43 | letter = 'comma'
44 | elif letter == '(':
45 | letter = 'braketop'
46 | elif letter == ')':
47 | letter = 'braketcl'
48 | elif letter == '-':
49 | letter = 'hiphen'
50 | writee(letter)
51 |
52 |
53 | def worddd(Input):
54 | wordlist = Input.split(' ')
55 | for i in wordlist:
56 | letterwrite(i)
57 | writee('space')
58 |
59 |
60 | if __name__ == '__main__':
61 | try:
62 | with open('ml.txt', 'r') as file:
63 | data = file.read().replace('\n', '')
64 |
65 | with open('final_output.pdf', 'w') as file:
66 | pass
67 |
68 | l = len(data)
69 | nn = len(data) // 600
70 | chunks, chunk_size = len(data), len(data) // (nn + 1)
71 | p = [data[i:i + chunk_size] for i in range(0, chunks, chunk_size)]
72 |
73 | for i in range(0, len(p)):
74 | worddd(p[i])
75 | writee('\n')
76 | BG.save('%doutt.png' % i)
77 | BG1 = Image.open("myfont/bg.png")
78 | BG = BG1
79 | gap = 0
80 | _ = 0
81 | except ValueError as E:
82 | print("{}\nTry again".format(E))
83 |
84 | imagelist = []
85 | for i in range(0, len(p)):
86 | imagelist.append('%doutt.png' % i)
87 |
88 | #Converting images to pdf
89 | #Source:https://datatofish.com/images-to-pdf-python/
90 |
91 |
92 | def pdf_creation(PNG_FILE, flag=False):
93 | rgba = Image.open(PNG_FILE)
94 | rgb = Image.new('RGB', rgba.size, (255, 255, 255)) # white background
95 | rgb.paste(rgba, mask=rgba.split()[3]) # paste using alpha channel as mask
96 | rgb.save('final_output.pdf',
97 | append=flag) #Now save multiple images in same pdf file
98 |
99 |
100 | #First create a pdf file if not created
101 | pdf_creation(imagelist.pop(0))
102 |
103 | #Now I am opening each images and converting them to pdf
104 | #Appending them to pdfs
105 | for PNG_FILE in imagelist:
106 | pdf_creation(PNG_FILE, flag=True)
107 |
108 |
--------------------------------------------------------------------------------