1. Home
  2. Foxit Quick PDF Library
  3. Generate an invoice programmatically as a PDF

Generate an invoice programmatically as a PDF

Generating PDF files is easy using Foxit Quick PDF Library. In this example we will demonstrate how to programmatically create an invoice as a PDF. In this example we’ll use a range of functions to create the content for the page. The company logo is created using paths, but that section of code could be simplified just by adding an image using the AddImageFromFile function.

/* Create a PDF invoice */
 
// Set page origin to top left, default is the bottom left
 
DPL.SetOrigin(1);
 
// Invoice number text
 
DPL.SetTextSize(20);
DPL.DrawText(55, 65, "Invoice #");
DPL.SetTextColor(0, 0.5, 1);
DPL.DrawText(140, 65, "1564824");
 
// Company logo
 
DPL.SetFillColor(0, 0, 0);
DPL.SetLineColor(1, 1, 1);
DPL.DrawCircle(475, 15, 5, 2);
DPL.DrawCircle(490, 20, 10, 2);
DPL.DrawCircle(505, 25, 15, 2);
DPL.DrawCircle(520, 30, 20, 2);
DPL.DrawCircle(535, 35, 25, 2);
DPL.DrawCircle(550, 40, 30, 2);
 
DPL.DrawHTMLTextBox(470, 38, 100, 100, "THE
CIRCLE
COMPANY.");
 
// Draw some lines to give the invoice structure
 
DPL.SetLineColor(0, 0, 0);
DPL.DrawLine(20, 150, 592, 150);
DPL.DrawLine(20, 200, 592, 200);
DPL.DrawLine(400, 250, 592, 250);
 
// Text color for body
 
DPL.SetTextColor(0, 0, 0);
 
// Invoice headings
 
DPL.SetTextSize(12);
DPL.DrawText(50, 145, "Description");
DPL.DrawText(225, 145, "Quantity");
DPL.DrawText(375, 145, "Unit Price");
DPL.DrawText(525, 145, "Amount");
 
// Invoice content
 
DPL.SetTextSize(10);
DPL.DrawText(50, 195, "Fictional Product 1.0");
DPL.DrawText(245, 195, "5");
DPL.DrawText(385, 195, "199.00");
DPL.DrawText(532, 195, "995.00");
 
// Invoice totals
 
DPL.DrawText(455, 225, "Sub-Total");
DPL.DrawText(532, 225, "$995.00");
DPL.DrawText(455, 245, "Tax");
DPL.DrawText(532, 245, "$0.00");
DPL.DrawHTMLText(455, 270, 100, "<b>Total</b>");
DPL.DrawHTMLText(532, 270, 100, "<b>$995.00</b>");
 
// Payment due date
 
DPL.DrawHTMLText(50, 400, 100, "<b>Due Date: Today</b>");
 
// Save the invoice
 
DPL.SaveToFile("invoice.pdf");

The output looks like this:

Updated on April 10, 2017

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial