

- #TXT TO PDF CONVERTER INSTALL#
- #TXT TO PDF CONVERTER GENERATOR#
- #TXT TO PDF CONVERTER MOD#
- #TXT TO PDF CONVERTER UPDATE#
- #TXT TO PDF CONVERTER SOFTWARE#
These basic files consist of ASCII characters, however, other character sets may be used in non-English speaking countries. It allows you to create and read PDF files, compress and optimize PDF files, watermark PDF files, process PDF files, and much more.Ĭheck out the gofpdf GitHub repository if you are interested in exploring more about the package and its features.Documents with the. Unipdf is a gofpdf alternative that you would like to consider if you are interested in advanced page manipulations. We also have seen how easy it is to convert a text file to PDF format using the gofpdf library. In this article, we took a look at the gofpdf library and some of its features for generating documents.

Now, save and run the command go run main.go and a hello.pdf file should be generated in the current directory. Morbi nec tellus ac mi ornare blandit eu sit amet velit. Proin a aliquet mauris, sed rutrum lorem. Suspendisse pulvinar velit a lectus tristique, sed congue nisi mattis. Suspendisse tincidunt nunc vitae nibh condimentum lacinia. Phasellus purus mauris, mollis in condimentum sed, convallis dapibus neque. Sed tincidunt est vitae ligula sodales, pellentesque aliquet libero ullamcorper. Vivamus molestie purus nec orci porta commodo vel ut erat. Donec varius leo quis augue finibus gravida sit amet vitae ligula. Here, we write the text content in the cell and save to a file called hello.pdf.Ĭreate a file called lorem.txt and paste the following text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. We move the cursor to the start of the line, then, we set the font size to 14, the font weight to normal, and we create a pdf.Multicell that spans the entire width of the page. Pdf.MultiCell(width, 10, string(text), "", "", false)Įrr = pdf.OutputFileAndClose("hello.pdf")įirst, we read the text from the lorem.txt file, then we write the title of the document as we did before except we change the text to Lorem Ipsum. Text, err := ioutil.ReadFile("lorem.txt") Replace the code in your main.go file with the following: package main To convert a text file to a PDF, first we read the file using the io/ioutil library and write the output to a PDF file. Then, we save it to a file called "hello.pdf" and we write out a message saying the PDF was created successfully.Īfter this, run the command go run main.go to run the code, and you should see a PDF file generated in your current directory. We proceed to create a cell that’s 40mm wide and 10mm high and we write the text “Hello world” in there. Then, we set the font to Arial with a weight of bold and set the font size to 16. Here, we create a new PDF object with gofpdf.New, set the orientation to portrait, the unit system to millimeters, the paper size to A4, and we leave the option for the font directory as a blank string. Įrr := pdf.OutputFileAndClose("hello.pdf")įmt.Println("PDF generated successfully")
#TXT TO PDF CONVERTER UPDATE#
In order to create our first PDF, we’ll update the main.go file with the following code.

#TXT TO PDF CONVERTER MOD#
Next, run go mod tidy to download all the required packages. Now, in your terminal, navigate to the directory containing your main.go file and run the command go mod init go-pdf to initialize Go modules in the current directory.
#TXT TO PDF CONVERTER INSTALL#
We’ll install two packages, which in this case are the fmt library for printing text out to the console and the /jung-kurt/gofpdf package for converting a text file to PDF format.Ĭreate a file called main.go and paste in the following code: package main The package has no other dependencies other than the Golang standard library. The package comes with a lot of features like page compression clipping barcodes inclusion of JPEG, PNG, GIF, TIFF and basic path-only SVG images document protection charts, etc. The repository is currently archived and read-only, but the package is stable enough for our use case. It was created by Jung Kurt and you can find the GitHub repository here.
#TXT TO PDF CONVERTER GENERATOR#
The gofpdf package is a document generator with high-level support for text, drawing and images. In this article, we will be taking a look at how we can convert a text file to PDF format with Golang. Its popularity has no doubt given rise to a lot of packages being built by the Go community, and we will take a look at one of these packages today. Golang is one of the fastest growing languages today. In my spare time, I enjoy watching sci-fi movies and cheering for Arsenal FC.
#TXT TO PDF CONVERTER SOFTWARE#
Emmanuel John Follow I'm a full-stack software developer, mentor, and writer.
