Friday, February 12, 2016

PDFPrinter Class!

PDFPrinter is a class created to provide an easy way to generate simple PDF documents in Qt Creator (C++). The PDFPrinter is an open source project that can be found at Github.


The PDFPrinter class was created using some native classes from Qt, for example: QPrinter and QPainter.
The main objective of PDFPrinter is to make life easier for software developers who want to generate simple PDF documents. You don't need to bother in align the text on the page size, align or resize the images, or break a page, the PDFPrinter class does all of it for you.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 // Now you can create an object of the PDFPrinter class:  
 PDFPrinter pdfPrinter;  

 // Call the 'start' function and pass the file path where do you want to save the PDF  
 pdfPrinter.start("C:\\Desktop\\test.pdf");  

 // You can set the margins of the page in percentage (e.g. 10%)  
 pdfPrinter.setHorizontalMargin(10);  
 pdfPrinter.setVerticalMargin(10);  

 // You can set a font size  
 pdfPrinter.setFontSize(24);  

 // You can set the font as bold  
 pdfPrinter.setTextBold(true);  

 // You can print a title in the center of the page (horizontal center)  
 pdfPrinter.printText("My Report", QtPrinter::Center);  

 // You can print a line  
 pdfPrinter.printLine();  

 // You can print your text  
 pdfPrinter.printText("This is my first report created with the PDFPrinter class!", QtPrinter::Left);  

 // And finally you need to call the end function  
 pdfPrinter.end(); 
To know more about the PDFPrinter class please visit: https://github.com/kelvins/PDFPrinter

No comments:

Post a Comment