示例#1
0
        private static void ReportBuilderPatronage(List <ListStatementPatRetainItem> stateList,
                                                   int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
                                                   string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderPatronage: ";

            string SHID               = "";
            string equityCropYear     = "";
            string rptTitle           = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr       = "";
            float  pdfYPos            = 0;
            float  pdfXPos            = -4;

            Document        document    = null;
            PdfWriter       writer      = null;
            PdfPTable       bottomTable = null;
            ColumnText      ct          = null;
            PdfImportedPage pdfImport   = null;

            CertificateEvent pgEvent = null;

            try {
                if (stateList.Count > 0)
                {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList)
                {
                    if (rptTitle.Length == 0)
                    {
                        rptTitle = qualifiedStr.ToUpper() + " PATRONAGE REFUND NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //PdfReader reader = new PdfReader(...);
                        //for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
                        //    reader.getPageN(k).put(PdfName.ROTATE, new PdfNumber(90));
                        //}
                        //PdfStamper stp = new PdfStamper(reader, ...);
                        //stp.close();
                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //string tmpFilePath = sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate.pdf");
                        //PdfReader rdr = new PdfReader(tmpFilePath);
                        //rdr.GetPageN(1).Put(PdfName.ROTATE, new PdfNumber(90));

                        //Document docCopy = new Document(rdr.GetPageSizeWithRotation(1));
                        //PdfCopy pCopy = new PdfCopy(docCopy, new System.IO.FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read));

                        //docCopy.Open();

                        //docCopy.AddCreationDate();
                        //docCopy.AddCreator("");
                        //docCopy.AddTitle("CertificateTemplate.pdf");

                        //pCopy.AddPage(pCopy.GetImportedPage(rdr, 1));
                        //docCopy.Close();

                        //using (System.IO.FileStream fsTmpOut = new FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) {

                        //    PdfStamper tmpStamp = new PdfStamper(rdr, fsTmpOut);
                        //    tmpStamp.Close();
                        //}

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string    _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder   = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        // ================================================================================================================
                        // FROM JPG -- Uses a jpg image as the under layer!!! This ROUGHLY WORKS -- NEEDS HELP !
                        // ================================================================================================================
                        //string _logo = sigImagePath.Replace("CertificateSignature.gif", "MyBorders.gif");

                        //iTextSharp.text.Image imgBack = PdfReports.GetImage(_logo, Convert.ToInt32(document.Right - document.RightMargin - document.LeftMargin),
                        //    Convert.ToInt32(document.Top - document.TopMargin - document.BottomMargin), iTextSharp.text.Element.ALIGN_CENTER);

                        //float imageYPos = document.Top - imgBack.Height;
                        //float imageXPos = 0;

                        //// To position an image  at (x,y) use addImage(image, image_width, 0, 0, image_height, x, y)
                        //writer.DirectContentUnder.AddImage(imgBack, imgBack.Width, 0, 0, imgBack.Height, imageXPos, imageYPos);

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    }
                    else
                    {
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildPatronageBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomPatLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Total patronage refund: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Paid by check: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.PatInitPayment).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Patronage equity: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    ct.AddElement(bottomTable);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    //  this is odd, but use the RET layout for sig line.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
示例#2
0
        private static void ReportBuilderRetain(List<ListStatementPatRetainItem> stateList, 
			int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
            string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderRetain: ";

            string SHID = "";
            string equityCropYear = "";
            string rptTitle = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr = "";
            float pdfYPos = 0;
            float pdfXPos = -4;

            Document document = null;
            PdfWriter writer = null;
            PdfPTable bottomTable = null;
            ColumnText ct = null;
            PdfImportedPage pdfImport = null;

            CertificateEvent pgEvent = null;

            try {

                if (stateList.Count > 0) {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList) {

                    if (rptTitle.Length == 0) {
                        rptTitle = qualifiedStr.ToUpper() + " UNIT RETAIN NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null) {

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                            PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.

                    } else {

                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildRetainBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Amount: " + Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null) {

                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null) {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                    "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {

                if (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null) {
                    writer.Close();
                }
            }
        }
示例#3
0
        private static void ReportBuilderRetain(List <ListStatementPatRetainItem> stateList,
                                                int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
                                                string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderRetain: ";

            string SHID               = "";
            string equityCropYear     = "";
            string rptTitle           = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr       = "";
            float  pdfYPos            = 0;
            float  pdfXPos            = -4;

            Document        document    = null;
            PdfWriter       writer      = null;
            PdfPTable       bottomTable = null;
            ColumnText      ct          = null;
            PdfImportedPage pdfImport   = null;

            CertificateEvent pgEvent = null;

            try {
                if (stateList.Count > 0)
                {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList)
                {
                    if (rptTitle.Length == 0)
                    {
                        rptTitle = qualifiedStr.ToUpper() + " UNIT RETAIN NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                                                PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string    _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder   = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.
                    }
                    else
                    {
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildRetainBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Amount: " + Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null)
                {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                                "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
示例#4
0
        private static void ReportBuilderPatronage(List<ListStatementPatRetainItem> stateList, 
			int cropYear, DateTime certificateDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs,
            string sigName, string sigTitle, string sigImagePath)
        {
            const string METHOD_NAME = "ReportBuilderPatronage: ";

            string SHID = "";
            string equityCropYear = "";
            string rptTitle = "";
            string certificateDateStr = certificateDate.ToString(HEADER_DATE_FORMAT);
            string qualifiedStr = "";
            float pdfYPos = 0;
            float pdfXPos = -4;

            Document document = null;
            PdfWriter writer = null;
            PdfPTable bottomTable = null;
            ColumnText ct = null;
            PdfImportedPage pdfImport = null;

            CertificateEvent pgEvent = null;

            try {

                if (stateList.Count > 0) {
                    qualifiedStr = (stateList[0].Qualified.ToLower() == "qualified" ? "Qualified" : "NonQualified");
                }

                iTextSharp.text.Image imgSignature = PdfReports.GetImage(sigImagePath, 228, 68, iTextSharp.text.Element.ALIGN_LEFT);

                foreach (ListStatementPatRetainItem state in stateList) {

                    if (rptTitle.Length == 0) {
                        rptTitle = qualifiedStr.ToUpper() + " PATRONAGE REFUND NOTICE\n" + "CROP YEAR " + cropYear.ToString();
                    }

                    SHID = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null) {

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin,
                            PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin);

                        // we create a writer that listens to the document
                        // and directs a PDF-stream to a file
                        writer = PdfWriter.GetInstance(document, fs);

                        // Attach my override event handler(s)
                        pgEvent = new CertificateEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //PdfReader reader = new PdfReader(...);
                        //for (int k = 1; k <= reader.getNumberOfPages(); ++k) {
                        //    reader.getPageN(k).put(PdfName.ROTATE, new PdfNumber(90));
                        //}
                        //PdfStamper stp = new PdfStamper(reader, ...);
                        //stp.close();
                        // ** ROTATE ** ROTATE **  ---------------------------------------------------------------------------------------
                        //string tmpFilePath = sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate.pdf");
                        //PdfReader rdr = new PdfReader(tmpFilePath);
                        //rdr.GetPageN(1).Put(PdfName.ROTATE, new PdfNumber(90));

                        //Document docCopy = new Document(rdr.GetPageSizeWithRotation(1));
                        //PdfCopy pCopy = new PdfCopy(docCopy, new System.IO.FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read));

                        //docCopy.Open();

                        //docCopy.AddCreationDate();
                        //docCopy.AddCreator("");
                        //docCopy.AddTitle("CertificateTemplate.pdf");

                        //pCopy.AddPage(pCopy.GetImportedPage(rdr, 1));
                        //docCopy.Close();

                        //using (System.IO.FileStream fsTmpOut = new FileStream(sigImagePath.Replace("CertificateSignature.gif", "WorkTemplate90.pdf"),
                        //    System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read)) {

                        //    PdfStamper tmpStamp = new PdfStamper(rdr, fsTmpOut);
                        //    tmpStamp.Close();
                        //}

                        // ================================================================================================================
                        // FROM PDF -- Pulls a background image out of a pdf and uses it as the under layer! Works BUT NEEDS ADJUSTMENT
                        // ================================================================================================================
                        string _certBorderPath = sigImagePath.Replace("CertificateSignature.gif", "CertBorders.pdf");
                        PdfReader rdrCertBorder = new PdfReader(_certBorderPath);
                        pdfImport = writer.GetImportedPage(rdrCertBorder, 1); // import only page 1.

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        // ================================================================================================================
                        // FROM JPG -- Uses a jpg image as the under layer!!! This ROUGHLY WORKS -- NEEDS HELP !
                        // ================================================================================================================
                        //string _logo = sigImagePath.Replace("CertificateSignature.gif", "MyBorders.gif");

                        //iTextSharp.text.Image imgBack = PdfReports.GetImage(_logo, Convert.ToInt32(document.Right - document.RightMargin - document.LeftMargin),
                        //    Convert.ToInt32(document.Top - document.TopMargin - document.BottomMargin), iTextSharp.text.Element.ALIGN_CENTER);

                        //float imageYPos = document.Top - imgBack.Height;
                        //float imageXPos = 0;

                        //// To position an image  at (x,y) use addImage(image, image_width, 0, 0, image_height, x, y)
                        //writer.DirectContentUnder.AddImage(imgBack, imgBack.Width, 0, 0, imgBack.Height, imageXPos, imageYPos);

                        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

                    } else {

                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, rptTitle, logoUrl);
                        document.NewPage();
                    }

                    writer.DirectContentUnder.AddTemplate(pdfImport, pdfXPos, pdfYPos);

                    // =======================================================
                    // Build Report
                    // =======================================================

                    // Fill report Body
                    ct = pgEvent.GetColumnObject();
                    BuildPatronageBodyText(cropYear, qualifiedStr, ct);

                    // Add Bottom section -- Date, Amount, SigLine.
                    bottomTable = PdfReports.CreateTable(_bottomPatLayout, 0);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);
                    PdfReports.AddText2Table(bottomTable, "Dated: " + certificateDateStr, _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, "Total patronage refund: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.EquityAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Paid by check: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.PatInitPayment).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, "Patronage equity: ", _normalFont, "left");
                    PdfReports.AddText2Table(bottomTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, _bottomRetLayout.Length);
                    ct.AddElement(bottomTable);

                    //----------------------------------
                    // Add Signature
                    //----------------------------------
                    //  this is odd, but use the RET layout for sig line.
                    bottomTable = PdfReports.CreateTable(_bottomRetLayout, 0);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddImage2Table(bottomTable, imgSignature);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    // add signature info
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigName, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    PdfReports.AddText2Table(bottomTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(bottomTable, sigTitle, _normalFont);
                    PdfReports.AddText2Table(bottomTable, " ", _normalFont);

                    ct.AddElement(bottomTable);
                    ct.Go(false);
                }

                // ======================================================
                // Close document
                // ======================================================
                if (document != null) {

                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (writer == null) {
                    // Warn that we have no data.
                    WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria.");
                    throw (warn);
                }
            }
            catch (Exception ex) {
                string errMsg = "document is null: " + (document == null).ToString() + "; " +
                    "writer is null: " + (writer == null).ToString();
                WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex);
                throw (wscex);
            }
            finally {

                if (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null) {
                    writer.Close();
                }
            }
        }