Example of XML and Output PDF

DOList.xml
DOList.pdf

Page1
pg1.jpg

Page2
pg2.jpg

Page3
pg3.jpg

        public static void testOutletDOList()
        {
            Moon.PDFTemplateItextSharp.PDFTemplateItextSharp pdfTmpl =
    new Moon.PDFTemplateItextSharp.PDFTemplateItextSharp("DOList.xml");


            Hashtable headerData = new Hashtable();
            headerData.Add("{site_name}", "Big Corporation");
            headerData.Add("{site_add1}", "Address Line1");
            headerData.Add("{site_add2}", "Address Line2");
            headerData.Add("{site_add3}", "Address Line3");
            headerData.Add("{site_add4}", "Address Line4");
            headerData.Add("{site_tel}", "+01088990098");
            headerData.Add("{site_fax}", "+01088990097");

            headerData.Add("{order_no}", "DO-000001");
            headerData.Add("{delivery_date}", new DateTime(2011, 12, 31).ToShortDateString());


            headerData.Add("{sup_name}", "Supplier Company");
            headerData.Add("{sup_add1}", "Sup Address Line1");
            headerData.Add("{sup_add2}", "Sup Address Line2");
            headerData.Add("{sup_add3}", "Sup Address Line3");
            headerData.Add("{sup_add4}", "Sup Address Line4");
            headerData.Add("{sup_tel}", "+02099999999");
            headerData.Add("{sup_fax}", "+02099999998");

            headerData.Add("{outlet_name}", "Outlet Company");
            headerData.Add("{outlet_add1}", "Out Address Line1");
            headerData.Add("{outlet_add2}", "Out Address Line2");
            headerData.Add("{outlet_add3}", "Out Address Line3");
            headerData.Add("{outlet_add4}", "Out Address Line4");
            headerData.Add("{outlet_tel}", "+03088888888");
            headerData.Add("{outlet_fax}", "+03088888887");


            List<Hashtable> loopData = new List<Hashtable>();
            for (int i = 1; i < 100; i++)
            {
                Hashtable data = new Hashtable();
                data.Add("{no}", i);
                data.Add("{item_code}", "Item " + i);
                data.Add("{item_desc}", "Item Desc " + i);
                data.Add("{uom}", "PCS");
                data.Add("{delivery_qty}", 10);
                data.Add("{box_label}", "");

                loopData.Add(data);
            }
            
            Hashtable bodyData = new Hashtable();
            bodyData.Add("{remark}", "Please deliver ASAP. And make it a very very very long line of remark!");

            Hashtable footerData = new Hashtable();

            pdfTmpl.Draw(headerData, loopData, bodyData, footerData);

            System.IO.FileStream file = new System.IO.FileStream("DOList.pdf", System.IO.FileMode.Create);
            System.IO.MemoryStream mStream = pdfTmpl.Close();
            byte[] bytes = mStream.ToArray();
            file.Write(bytes, 0, bytes.Length);
            file.Close();
            mStream.Close();
        }

Last edited Jan 27, 2013 at 11:34 AM by cmwong, version 4

Comments

No comments yet.