public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);
            iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            iTextSharp.text.Font baseFontBig    = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
            Phrase p1Header = new Phrase("AHP RESULT", baseFontBig);

            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(3);

            //We will have to create separate cells to include image logo and 2 separate strings
            //Row 1
            PdfPCell pdfCell1 = new PdfPCell();
            PdfPCell pdfCell2 = new PdfPCell(p1Header);
            PdfPCell pdfCell3 = new PdfPCell();
            String   text     = "Page " + writer.PageNumber + " of ";

            //Add paging to header
            //{
            //    cb.BeginText();
            //    cb.SetFontAndSize(bf, 12);
            //    cb.SetTextMatrix(document.PageSize.GetRight(200), document.PageSize.GetTop(45));
            //    cb.ShowText(text);
            //    cb.EndText();
            //    float len = bf.GetWidthPoint(text, 12);
            //    //Adds "12" in Page 1 of 12
            //    cb.AddTemplate(headerTemplate, document.PageSize.GetRight(200) + len, document.PageSize.GetTop(45));
            //}
            //Add paging to footer
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 12);
                cb.SetTextMatrix(document.PageSize.GetRight(180), document.PageSize.GetBottom(30));
                cb.ShowText(text);
                cb.EndText();
                float len = bf.GetWidthPoint(text, 12);
                cb.AddTemplate(footerTemplate, document.PageSize.GetRight(180) + len, document.PageSize.GetBottom(30));
            }

            //Row 2
            PdfPCell pdfCell4 = new PdfPCell(new Phrase("Topic: " + currentTopicName, baseFontNormal));

            //Row 3
            //PdfPCell pdfCell5 = new PdfPCell(new Phrase("DATE:" + PrintTime.ToShortDateString(), baseFontBig));
            //PdfPCell pdfCell6 = new PdfPCell();
            //PdfPCell pdfCell7 = new PdfPCell(new Phrase("TIME:" + string.Format("{0:t}", DateTime.Now), baseFontBig));

            //set the alignment of all three cells and set border to 0
            pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER;
            pdfCell4.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell5.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER;
            //pdfCell7.HorizontalAlignment = Element.ALIGN_CENTER;

            pdfCell2.VerticalAlignment = Element.ALIGN_BOTTOM;
            pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfCell4.VerticalAlignment = Element.ALIGN_TOP;
            //pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            //pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            //pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE;

            pdfCell4.Colspan = 3;

            pdfCell1.Border = 0;
            pdfCell2.Border = 0;
            pdfCell3.Border = 0;
            pdfCell4.Border = 0;
            //pdfCell5.Border = 0;
            //pdfCell6.Border = 0;
            //pdfCell7.Border = 0;

            //add all three cells into PdfTable
            pdfTab.AddCell(pdfCell1);
            pdfTab.AddCell(pdfCell2);
            pdfTab.AddCell(pdfCell3);
            pdfTab.AddCell(pdfCell4);
            //pdfTab.AddCell(pdfCell5);
            //pdfTab.AddCell(pdfCell6);
            //pdfTab.AddCell(pdfCell7);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 70;
            //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER;

            //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable
            //first param is start row. -1 indicates there is no end row and all the rows to be included to write
            //Third and fourth param is x and y position to start writing
            pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent);
            //set pdfContent value

            //Move the pointer and draw line to separate header section from rest of page
            cb.MoveTo(40, document.PageSize.Height - 75);
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 75);
            cb.Stroke();

            //Move the pointer and draw line to separate footer section from rest of page
            cb.MoveTo(40, document.PageSize.GetBottom(50));
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));
            cb.Stroke();
        }
示例#2
0
 /**
 * Draws a horizontal line.
 * @param canvas the canvas to draw on
 * @param leftX      the left x coordinate
 * @param rightX the right x coordindate
 * @param y          the y coordinate
 */
 virtual public void DrawLine(PdfContentByte canvas, float leftX, float rightX, float y) {
     float w;
     if (Percentage < 0)
         w = -Percentage;
     else
         w = (rightX - leftX) * Percentage / 100.0f;
     float s;
     switch (Alignment) {
         case Element.ALIGN_LEFT:
             s = 0;
             break;
         case Element.ALIGN_RIGHT:
             s = rightX - leftX - w;
             break;
         default:
             s = (rightX - leftX - w) / 2;
             break;
     }
     canvas.SetLineWidth(LineWidth);
     if (LineColor != null)
         canvas.SetColorStroke(LineColor);
     canvas.MoveTo(s + leftX, y + offset);
     canvas.LineTo(s + w + leftX, y + offset);
     canvas.Stroke();
 }
示例#3
0
        public string ExportSelectedCustomerInPdf(ObservableCollection <ModelView.CustomerModelView> listCustomer)
        {
            try
            {
                System.IO.FileStream fs = new FileStream(@"C:\Politexniki\PDF Export\" + listCustomer[0].FirstName.ToString().ToUpper() + " " + listCustomer[0].LastName.ToString().ToUpper() + ".pdf", FileMode.Create);

                Document  document = new Document(PageSize.A4, 25, 25, 30, 1);
                PdfWriter writer   = PdfWriter.GetInstance(document, fs);

                // Open the document to enable you to write to the document
                document.Open();

                // Makes it possible to add text to a specific place in the document using
                // a X & Y placement syntax.
                PdfContentByte cb = writer.DirectContent;
                // Add a footer template to the document
                cb.AddTemplate(PdfFooter(cb), 30, -5);

                // Add a logo to the invoice
                iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(@"C:\Users\akech\source\Workspaces\Politexniki\BuildProcessTemplates\Politexniki\Politexniki_Client\Icons\plotexniki_logo.png");
                png.ScaleAbsolute(200, 55);
                png.SetAbsolutePosition(40, 750);
                cb.AddImage(png);

                // First we must activate writing
                cb.BeginText();

                // First we write out the header information

                // Start with the invoice type header
                WriteText(cb, "Λίστα Πελατών", 350, 800, f_cb, 14);
                // HEader details; invoice number, invoice date, due date and customer Id
                WriteText(cb, "Ποσότητα Πελατών", 350, 780, f_cb, 10);
                WriteText(cb, listCustomer.Count.ToString(), 480, 780, f_cn, 10);
                WriteText(cb, "Ημερομηνία", 350, 760, f_cb, 10);
                WriteText(cb, DateTime.Now.ToShortDateString(), 480, 760, f_cn, 10);
                cb.EndText();

                // Delivery address details
                int left_margin = 40;
                int top_margin  = 720;

                // Separate the header from the rows with a line
                // Draw a line by setting the line width and position
                cb.SetLineWidth(0f);
                cb.MoveTo(40, 750);
                cb.LineTo(560, 750);
                cb.Stroke();
                // Don't forget to call the BeginText() method when done doing graphics!
                cb.BeginText();

                // Before we write the lines, it's good to assign a "last position to write"
                // variable to validate against if we need to make a page break while outputting.
                // Change it to 510 to write to test a page break; the fourth line on a new page
                int lastwriteposition = 100;

                // Loop thru the rows in the rows table
                // Start by writing out the line headers
                top_margin  = 730;
                left_margin = 190;
                // Line headers
                WriteText(cb, "'Ονομα :", left_margin, top_margin, f_cb, 10);
                WriteText(cb, "Επώνυμο :", left_margin, top_margin - 20, f_cb, 10);
                WriteText(cb, "Όνομα και επώνυμο πατέρα :", left_margin, top_margin - 40, f_cb, 10);
                WriteText(cb, "Όνομα και επώνυμο μητέρας :", left_margin, top_margin - 60, f_cb, 10);
                WriteText(cb, "Ημερομηνία γέννησης :", left_margin, top_margin - 80, f_cb, 10);
                WriteText(cb, "Τόπος γέννησης :", left_margin, top_margin - 100, f_cb, 10);
                WriteText(cb, "Τηλέφωνο :", left_margin, top_margin - 120, f_cb, 10);
                WriteText(cb, "Αριθ. δελτ. ταυτότητας :", left_margin, top_margin - 140, f_cb, 10);
                WriteText(cb, "Τόπος κατοικίας :", left_margin, top_margin - 160, f_cb, 10);
                WriteText(cb, "Οδός :", left_margin, top_margin - 180, f_cb, 10);
                WriteText(cb, "Αριθμός :", left_margin, top_margin - 200, f_cb, 10);
                WriteText(cb, "Τ.Κ. :", left_margin, top_margin - 220, f_cb, 10);
                WriteText(cb, "Α.Φ.Μ. :", left_margin, top_margin - 240, f_cb, 10);
                WriteText(cb, "Δ.Ο.Υ. :", left_margin, top_margin - 260, f_cb, 10);

                // First item line position starts here
                top_margin  = 730;
                left_margin = 360;
                // Loop thru the table of items and set the linespacing to 12 points.
                // Note that we use the -= operator, the coordinates goes from the bottom of the page!
                foreach (ModelView.CustomerModelView customer in listCustomer)
                {
                    WriteText(cb, customer.FirstName, left_margin, top_margin, f_cn, 10);
                    WriteText(cb, customer.LastName, left_margin, top_margin - 20, f_cn, 10);
                    WriteText(cb, customer.FatherFullName, left_margin, top_margin - 40, f_cn, 10);
                    WriteText(cb, customer.MotherFullName, left_margin, top_margin - 60, f_cn, 10);
                    WriteText(cb, customer.Birthday, left_margin, top_margin - 80, f_cn, 10);
                    WriteText(cb, customer.PlaceOfBirth, left_margin, top_margin - 100, f_cn, 10);
                    WriteText(cb, customer.Telephone, left_margin, top_margin - 120, f_cn, 10);
                    WriteText(cb, customer.Id, left_margin, top_margin - 140, f_cn, 10);
                    WriteText(cb, customer.ResidencePlace, left_margin, top_margin - 160, f_cn, 10);
                    WriteText(cb, customer.Address, left_margin, top_margin - 180, f_cn, 10);
                    WriteText(cb, customer.Number.ToString(), left_margin, top_margin - 200, f_cn, 10);
                    WriteText(cb, customer.PostCode, left_margin, top_margin - 220, f_cn, 10);
                    WriteText(cb, customer.SocialNumber, left_margin, top_margin - 240, f_cn, 10);
                    WriteText(cb, customer.TaxPlace, left_margin, top_margin - 260, f_cn, 10);

                    // This is the line spacing, if you change the font size, you might want to change this as well.
                    top_margin -= 12;

                    // Implement a page break function, checking if the write position has reached the lastwriteposition
                    if (top_margin <= lastwriteposition)
                    {
                        // We need to end the writing before we change the page
                        cb.EndText();
                        // Make the page break
                        document.NewPage();
                        // Start the writing again
                        cb.BeginText();
                        // Assign the new write location on page two!
                        // Here you might want to implement a new header function for the new page
                        top_margin = 780;
                    }
                }

                // End the writing of text
                cb.EndText();
                // Close the document, the writer and the filestream!
                document.Close();
                writer.Close();
                fs.Close();

                _messageStatus = "Η εξαγωγή πελατών σε PDF ολοκληρώθηκε.";
            }
            catch (Exception e)
            {
                _messageStatus = e.Message;
                Log_Handler.LogHandling.Instance.StoreLog("PdfHandling", "ExportSelectedCustomerInPdf", e.Message, DateTime.Now);
            }

            return(_messageStatus);
        }
示例#4
0
        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal void WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)
        {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;
            float glueWidth = 0;

            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.GetLineLengthUtf32();
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            int separatorCount = line.GetSeparatorCount();
            if (separatorCount > 0) {
                glueWidth = line.WidthLeft / separatorCount;
            }
            else if (isJustified) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }

            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;
            float tabPosition = 0;

            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                Color color = chunk.Color;
                hScale = 1;

                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else {
                        width = chunk.Width;
                    }
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsSeparator()) {
                            width = glueWidth;
                            Object[] sep = (Object[])chunk.GetAttribute(Chunk.SEPARATOR);
                            IDrawInterface di = (IDrawInterface)sep[0];
                            bool vertical = (bool)sep[1];
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            if (vertical) {
                                di.Draw(graphics, baseXMarker, yMarker + descender, baseXMarker + line.OriginalWidth, ascender - descender, yMarker);
                            }
                            else {
                                di.Draw(graphics, xMarker, yMarker + descender, xMarker + width, ascender - descender, yMarker);
                            }
                        }
                        if (chunk.IsTab()) {
                            Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                            IDrawInterface di = (IDrawInterface)tab[0];
                            tabPosition = (float)tab[1] + (float)tab[3];
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            if (tabPosition > xMarker) {
                                di.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                            }
                            float tmp = xMarker;
                            xMarker = tabPosition;
                            tabPosition = tmp;
                        }
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((Color)bgr[0]);
                            float[] extra = (float[])bgr[1];
                            graphics.Rectangle(xMarker - extra[0],
                                yMarker + descender - extra[1] + chunk.TextRise,
                                width - subtract + extra[0] + extra[2],
                                ascender - descender + extra[1] + extra[3]);
                            graphics.Fill();
                            graphics.SetGrayFill(0);
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            Color scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (Color)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                float fsize = chunk.Font.Size;
                                graphics.SetLineWidth(ps[0] + fsize * ps[1]);
                                float shift = ps[2] + fsize * ps[3];
                                int cap2 = (int)ps[4];
                                if (cap2 != 0)
                                    graphics.SetLineCap(cap2);
                                graphics.MoveTo(xMarker, yMarker + shift);
                                graphics.LineTo(xMarker + width - subtract, yMarker + shift);
                                graphics.Stroke();
                                if (scolor != null)
                                    graphics.ResetGrayStroke();
                                if (cap2 != 0)
                                    graphics.SetLineCap(0);
                            }
                            graphics.SetLineWidth(1);
                        }
                        if (chunk.IsAttribute(Chunk.ACTION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            text.AddAnnotation(new PdfAnnotation(writer, xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size, (PdfAction)chunk.GetAttribute(Chunk.ACTION)));
                        }
                        if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
                            String filename = (String)obj[0];
                            if (obj[1] is String)
                                RemoteGoto(filename, (String)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + chunk.Font.Size, 0));
                        }
                        if (chunk.IsAttribute(Chunk.GENERICTAG)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + chunk.Font.Size);
                            IPdfPageEvent pev = writer.PageEvent;
                            if (pev != null)
                                pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
                        }
                        if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            float fontSize = chunk.Font.Size;
                            float ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                            float descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                            PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
                            annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
                            text.AddAnnotation(annot);
                        }
                        float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
                        object hs = chunk.GetAttribute(Chunk.HSCALE);
                        if (paramsx != null || hs != null) {
                            float b = 0, c = 0;
                            if (paramsx != null) {
                                b = paramsx[0];
                                c = paramsx[1];
                            }
                            if (hs != null)
                                hScale = (float)hs;
                            text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
                        }
                        if (chunk.IsImage()) {
                            Image image = chunk.Image;
                            float[] matrix = image.Matrix;
                            matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
                            matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
                            graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
                            text.MoveText(xMarker + lastBaseFactor + image.ScaledWidth - text.XTLM, 0);
                        }
                    }
                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (chunk.Font.CompareTo(currentFont) != 0) {
                    currentFont = chunk.Font;
                    text.SetFontAndSize(currentFont.Font, currentFont.Size);
                }
                float rise = 0;
                Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
                int tr = 0;
                float strokeWidth = 1;
                Color strokeColor = null;
                object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
                if (textRender != null) {
                    tr = (int)textRender[0] & 3;
                    if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                        text.SetTextRenderingMode(tr);
                    if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
                        strokeWidth = (float)textRender[1];
                        if (strokeWidth != 1)
                            text.SetLineWidth(strokeWidth);
                        strokeColor = (Color)textRender[2];
                        if (strokeColor == null)
                            strokeColor = color;
                        if (strokeColor != null)
                            text.SetColorStroke(strokeColor);
                    }
                }
                if (fr != null)
                    rise = (float)fr;
                if (color != null)
                    text.SetColorFill(color);
                if (rise != 0)
                    text.SetTextRise(rise);
                if (chunk.IsImage()) {
                    adjustMatrix = true;
                }
                else if (chunk.IsHorizontalSeparator()) {
                    PdfTextArray array = new PdfTextArray();
                    array.Add(-glueWidth * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                else if (chunk.IsTab()) {
                    PdfTextArray array = new PdfTextArray();
                    array.Add((tabPosition - xMarker) * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                // If it is a CJK chunk or Unicode TTF we will have to simulate the
                // space adjustment.
                else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
                    if (hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(s);
                    else {
                        float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
                        PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
                        int lastIdx = idx;
                        while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
                            textArray.Add(spaceCorrection);
                            textArray.Add(s.Substring(lastIdx, idx - lastIdx));
                            lastIdx = idx;
                        }
                        textArray.Add(spaceCorrection);
                        textArray.Add(s.Substring(lastIdx));
                        text.ShowText(textArray);
                    }
                }
                else {
                    if (isJustified && hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale);
                    }
                    text.ShowText(chunk.ToString());
                }

                if (rise != 0)
                    text.SetTextRise(0);
                if (color != null)
                    text.ResetRGBColorFill();
                if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                    text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                if (strokeColor != null)
                    text.ResetRGBColorStroke();
                if (strokeWidth != 1)
                    text.SetLineWidth(1);
                if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
                    adjustMatrix = true;
                    text.SetTextMatrix(xMarker, yMarker);
                }
            }
            if (isJustified) {
                text.SetWordSpacing(0);
                text.SetCharacterSpacing(0);
                if (line.NewlineSplit)
                    lastBaseFactor = 0;
            }
            if (adjustMatrix)
                text.MoveText(baseXMarker - text.XTLM, 0);
            currentValues[0] = currentFont;
            currentValues[1] = lastBaseFactor;
        }
示例#5
0
        public string ExportAllCustomersInPdf(ObservableCollection <ModelView.CustomerModelView> listCustomer)
        {
            try
            {
                System.IO.FileStream fs = new FileStream(@"C:\Politexniki\PDF Export\" + "Customers_" + DateTime.Now.Month + "_" + DateTime.Now.Year + ".pdf", FileMode.Create);

                Document  document = new Document(PageSize.A4, 25, 25, 30, 1);
                PdfWriter writer   = PdfWriter.GetInstance(document, fs);

                // Open the document to enable you to write to the document
                document.Open();

                // Makes it possible to add text to a specific place in the document using
                // a X & Y placement syntax.
                PdfContentByte cb = writer.DirectContent;
                // Add a footer template to the document
                cb.AddTemplate(PdfFooter(cb), 30, 1);

                // Add a logo to the invoice
                iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(@"C:\Users\akech\source\Workspaces\Politexniki\BuildProcessTemplates\Politexniki\Politexniki_Client\Icons\plotexniki_logo.png");
                png.ScaleAbsolute(200, 55);
                png.SetAbsolutePosition(40, 750);
                cb.AddImage(png);

                // First we must activate writing
                cb.BeginText();

                // First we write out the header information

                // Start with the invoice type header
                WriteText(cb, "Λίστα Πελατών", 350, 800, f_cb, 14);
                // HEader details; invoice number, invoice date, due date and customer Id
                WriteText(cb, "Ποσότητα Πελατών", 350, 780, f_cb, 10);
                WriteText(cb, listCustomer.Count.ToString(), 480, 780, f_cn, 10);
                WriteText(cb, "Ημερομηνία", 350, 760, f_cb, 10);
                WriteText(cb, DateTime.Now.ToShortDateString(), 480, 760, f_cn, 10);
                cb.EndText();

                // Delivery address details
                int left_margin = 40;
                int top_margin  = 720;

                // Separate the header from the rows with a line
                // Draw a line by setting the line width and position
                cb.SetLineWidth(0f);
                cb.MoveTo(40, 750);
                cb.LineTo(560, 750);
                cb.Stroke();
                // Don't forget to call the BeginText() method when done doing graphics!
                cb.BeginText();

                // Before we write the lines, it's good to assign a "last position to write"
                // variable to validate against if we need to make a page break while outputting.
                // Change it to 510 to write to test a page break; the fourth line on a new page
                int lastwriteposition = 100;

                // Loop thru the rows in the rows table
                // Start by writing out the line headers
                top_margin  = 730;
                left_margin = 40;
                // Line headers
                WriteText(cb, "'Ονομα και Επίθετο", left_margin, top_margin, f_cb, 10);
                WriteText(cb, "Διεύθηνση", left_margin + 150, top_margin, f_cb, 10);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Qty", left_margin + 415, top_margin, 0);
                WriteText(cb, "Τηλέφωνο", left_margin + 320, top_margin, f_cb, 10);
                //cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Price", left_margin + 495, top_margin, 0);
                //writeText(cb, "Curr", left_margin + 500, top_margin, f_cb, 10);

                // First item line position starts here
                top_margin = 700;

                // Loop thru the table of items and set the linespacing to 12 points.
                // Note that we use the -= operator, the coordinates goes from the bottom of the page!
                foreach (ModelView.CustomerModelView customer in listCustomer)
                {
                    WriteText(cb, customer.FirstName + " " + customer.LastName, left_margin, top_margin, f_cn, 10);
                    WriteText(cb, customer.Address, left_margin + 150, top_margin, f_cn, 10);
                    //cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, drItem["invoicedQuantity"].ToString(), left_margin + 415, top_margin, 0);
                    WriteText(cb, customer.Telephone, left_margin + 320, top_margin, f_cn, 10);
                    //cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, drItem["price"].ToString(), left_margin + 495, top_margin, 0);
                    //writeText(cb, drItem["currency"].ToString(), left_margin + 500, top_margin, f_cn, 10);

                    // This is the line spacing, if you change the font size, you might want to change this as well.
                    top_margin -= 12;

                    // Implement a page break function, checking if the write position has reached the lastwriteposition
                    if (top_margin <= lastwriteposition)
                    {
                        // We need to end the writing before we change the page
                        cb.EndText();
                        // Make the page break
                        document.NewPage();
                        // Start the writing again
                        cb.BeginText();
                        // Assign the new write location on page two!
                        // Here you might want to implement a new header function for the new page
                        top_margin = 780;
                    }
                }

                //top_margin -= 80;
                //left_margin = 350;
                // End the writing of text
                cb.EndText();
                // Close the document, the writer and the filestream!
                document.Close();
                writer.Close();
                fs.Close();

                _messageStatus = "Η εξαγωγή ολοκληρώθηκε.";
            }
            catch (Exception e)
            {
                _messageStatus = e.Message;
                Log_Handler.LogHandling.Instance.StoreLog("PdfHandling", "ExportAllCustomersInPdf", e.Message, DateTime.Now);
            }

            return(_messageStatus);
        }
示例#6
0
        public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
        {
            base.OnEndPage(writer, document);
            iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            iTextSharp.text.Font baseFontBig    = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);
            Font fonteNormal = new Font(Font.FontFamily.TIMES_ROMAN, 7, Font.BOLD);

            //Create PdfTable object
            PdfPTable pdfTab = new PdfPTable(3);

            pdfTab.TotalWidth      = document.PageSize.Width - 80f;
            pdfTab.WidthPercentage = 100;
            float[] larguras = new float[] { 2f, 0.5f, 7f };
            pdfTab.SetWidths(larguras);
            PdfPCell celulaIcone;
            PdfPCell celulaTexto;
            PdfPCell celulaLogo;

            celulaLogo = new PdfPCell();
            ImagemLogo.ScaleAbsolute(100, 50);
            celulaLogo.AddElement(ImagemLogo);
            celulaLogo.Border  = 0;
            celulaLogo.Rowspan = 3;
            pdfTab.AddCell(celulaLogo);
            celulaIcone        = new PdfPCell();
            celulaIcone.Border = 0;
            ImagemEmail.ScaleAbsolute(12, 12);
            celulaIcone.AddElement(ImagemEmail);
            pdfTab.AddCell(celulaIcone);
            celulaTexto        = new PdfPCell(new Phrase("*****@*****.**", fonteNormal));
            celulaTexto.Border = 0;
            pdfTab.AddCell(celulaTexto);

            celulaIcone        = new PdfPCell();
            celulaIcone.Border = 0;
            ImagemWhats.ScaleAbsolute(12, 12);
            celulaIcone.AddElement(ImagemWhats);
            pdfTab.AddCell(celulaIcone);
            celulaTexto        = new PdfPCell(new Phrase("(51) 00035-3739", fonteNormal));
            celulaTexto.Border = 0;
            pdfTab.AddCell(celulaTexto);

            celulaIcone        = new PdfPCell();
            celulaIcone.Border = 0;
            ImagemMaps.ScaleAbsolute(12, 12);
            celulaIcone.AddElement(ImagemMaps);
            pdfTab.AddCell(celulaIcone);
            celulaTexto        = new PdfPCell(new Phrase("Rua Hoefel Sander, 165, Fazenda São Borja - São Leopoldo - RS | CEP 93044-830", fonteNormal));
            celulaTexto.Border = 0;
            pdfTab.AddCell(celulaTexto);

            //Add paging to footer
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 10);
                cb.SetTextMatrix(document.PageSize.GetLeft(190), document.PageSize.GetBottom(30));
                cb.ShowText("Entre Rodas Assistência Técnica Automotiva");
                cb.EndText();
                float len = bf.GetWidthPoint("text", 12);
                cb.AddTemplate(footerTemplate, document.PageSize.GetRight(80) + len, document.PageSize.GetBottom(30));
            }
            pdfTab.WriteSelectedRows(0, -1, 110, document.PageSize.Height - 10, writer.DirectContent);
            //Move the pointer and draw line to separate header section from rest of page
            cb.MoveTo(40, document.PageSize.Height - 70);
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 70);
            cb.Stroke();
            //Move the pointer and draw line to separate footer section from rest of page
            cb.MoveTo(40, document.PageSize.GetBottom(50));
            cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));
            cb.Stroke();
        }
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            int hdrStartLeft, hdrStartTop;

            base.OnEndPage(writer, document);
            PdfContentByte canvas = writer.DirectContent;

            text = "Page " + writer.PageNumber.ToString() + " of ";
            iTextSharp.text.Rectangle pageSize = document.PageSize;

            // hdrStartLeft = CInt(ConfigurationManager.AppSettings("hdrStartLeft"))
            // hdrStartTop = CInt(ConfigurationManager.AppSettings("hdrStartTop"))

            DataTable dtP = new DataTable(); // Patient Details

            dtP = db.GetPatient(Convert.ToInt32(HttpContext.Current.Session["patientid"]));

            hdrStartLeft = 140;
            hdrStartTop  = 720;

            if (Convert.ToBoolean(dtP.Rows[0]["UseLogo"]) == false)
            {
                var logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Images/team-rehab-logo-prnt.jpg"));
                logo.SetAbsolutePosition(150, 750);
                document.Add(logo);
            }
            else
            {
                Byte[] bytes = (Byte[])dtP.Rows[0]["LogoFile"];

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bytes);

                image.SetAbsolutePosition(140, 750);
                document.Add(image);
            }

            if (HttpContext.Current.Session["NoteType"].ToString() == "PPOC" | HttpContext.Current.Session["NoteType"].ToString() == "PPOC2")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Plan Of Care - Initial Evaluation", titleFont), 320,
                                           hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PTREAT")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Daily Note", titleFont), 330, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PMN")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Medical Necessity", titleFont), 330, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PPOCRE")
            {
                DataTable dtPV = new DataTable();
                dtPV = db.GetPatVisits(Convert.ToInt32(HttpContext.Current.Session["patientid"]));
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Visits " + dtPV.Rows[0]["Visits"].ToString(), bodyFont), 40, hdrStartTop + 5, 0);
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("POC - Re-Evaluation", titleFont), 350, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PMV")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Missed Visit", titleFont), 330, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PCOMM")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Physicians Communication", titleFont), 340, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PDIS")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Discharge", titleFont), 350, hdrStartTop + 5, 0);
            }
            else if (HttpContext.Current.Session["NoteType"].ToString() == "PFCE")
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Functional Capacity Evaluation", titleFont), 320, hdrStartTop + 5, 0);
            }


            string strSQL;
            // DBHelper db = new DBHelper();
            DataTable dtD         = new DataTable(); // Document Details
            DataTable dtPIC       = new DataTable(); // Pat Insurance Claim Num
            DataTable dtDoS       = new DataTable(); // DoS
            DataTable dtPatVisits = new DataTable(); // Patient Visits
            DataTable dtTher      = new DataTable(); // Treating Therapist

            dtD   = db.GetDocDateOfService(Convert.ToInt32(HttpContext.Current.Session["docrowid"]));
            dtPIC = db.GetPatInsuranceClm(Convert.ToInt32(HttpContext.Current.Session["patientid"]),
                                          Convert.ToInt32(HttpContext.Current.Session["docrowid"]));
            dtPatVisits = db.GetPatVisits(Convert.ToInt32(HttpContext.Current.Session["patientid"]));
            if (HttpContext.Current.Session["UserRole"].ToString().Trim() == "Therapist")
            {
                dtTher = db.GetDocTherapist(Convert.ToInt32(HttpContext.Current.Session["user"]));
            }
            else
            {
                dtTher = db.GetDocTherapistRpt(Convert.ToInt32(HttpContext.Current.Session["docrowid"]));
            }
            dtPIC.Columns[0].MaxLength = 50;
            if (dtPIC.Rows.Count > 0)
            {
                dtPIC.Rows[0]["ClmNoTxt"] = "Claim Number";
                dtPIC.AcceptChanges();
            }

            canvas.MoveTo(10, hdrStartTop);
            canvas.LineTo(580, hdrStartTop);
            canvas.Stroke();

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Patient's Name", boldTableFont), hdrStartLeft, hdrStartTop - 15, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["PatientName"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 15, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Date Of Service", boldTableFont), hdrStartLeft + 300, hdrStartTop - 15, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtD.Rows[0]["DateOfService"].ToString(), bodyFont), hdrStartLeft + 310, hdrStartTop - 15, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("DOB", boldTableFont), hdrStartLeft, hdrStartTop - 30, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["BirthDate"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 30, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Medical Record", boldTableFont), hdrStartLeft, hdrStartTop - 45, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["MedicalRecordNum"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 45, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("SOC Date", boldTableFont), hdrStartLeft + 300, hdrStartTop - 45, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["firstvisitdate"].ToString(), bodyFont), hdrStartLeft + 310, hdrStartTop - 45, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Treating Therapist", boldTableFont), hdrStartLeft, hdrStartTop - 60, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtTher.Rows[0]["Name"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 60, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Clinic Phone", boldTableFont), hdrStartLeft + 300, hdrStartTop - 60, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["ClinicPhone"].ToString(), bodyFont), hdrStartLeft + 310, hdrStartTop - 60, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Referring Physican", boldTableFont), hdrStartLeft, hdrStartTop - 75, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(HttpContext.Current.Session["PrintName"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 75, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Clinic Fax", boldTableFont), hdrStartLeft + 300, hdrStartTop - 75, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["Fax"].ToString(), bodyFont), hdrStartLeft + 310, hdrStartTop - 75, 0);

            ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Treating Clinic", boldTableFont), hdrStartLeft, hdrStartTop - 90, 0);
            ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtP.Rows[0]["MarketingclinicName"].ToString(), bodyFont), hdrStartLeft + 10, hdrStartTop - 90, 0);

            if (dtP.Rows[0]["PatientCondition"].ToString() == "")
            {
            }
            else
            {
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Claim Number", boldTableFont), hdrStartLeft + 300, hdrStartTop - 90, 0);
                ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dtPIC.Rows[0]["ClaimNo"].ToString(), bodyFont), hdrStartLeft + 310, hdrStartTop - 90, 0);
            }

            canvas.MoveTo(10, hdrStartTop - 100);
            canvas.LineTo(580, hdrStartTop - 100);
            canvas.Stroke();
        }
示例#8
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            StringBuilder strCadena  = new StringBuilder();
            Font          ftHeader   = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL));
            Font          ftFooter   = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL));
            Font          ftHeaderB  = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD));
            Font          ftFooterB  = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.BOLD));
            Font          ftHeader30 = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 30, Font.NORMAL));
            Font          ftHeader11 = new Font(FontFactory.GetFont(FontFactory.HELVETICA, 11, Font.NORMAL));

            Rectangle page = document.PageSize;

            #region Header
            PdfPTable tblHeaderA = new PdfPTable(1);
            PdfPTable tblHeaderB = new PdfPTable(1);
            PdfPTable tblHeaderC = new PdfPTable(1);
            tblHeaderA.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
            tblHeaderA.DefaultCell.Border = Rectangle.NO_BORDER;
            tblHeaderA.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

            tblHeaderB.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
            tblHeaderB.DefaultCell.Border = Rectangle.NO_BORDER;
            tblHeaderB.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

            tblHeaderC.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
            tblHeaderC.DefaultCell.Border = Rectangle.NO_BORDER;
            tblHeaderC.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

            float[] ancho_columnas = new float[2];
            ancho_columnas[0] = 120;
            ancho_columnas[1] = tblHeaderA.TotalWidth - 120;
            PdfPTable tblHeader1 = new PdfPTable(ancho_columnas);

            iTextSharp.text.Image imgEmpresa = iTextSharp.text.Image.GetInstance(_strMapPath + _strLogoEmpresa);
            imgEmpresa.SetAbsolutePosition(45, 700);
            imgEmpresa.ScalePercent(_flEscala, _flEscala);
            document.Add(imgEmpresa);

            // iTextSharp.text.Imagen de la empresa
            PdfPCell celda = new PdfPCell();
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_MIDDLE;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader1.AddCell(celda);

            // Datos Fiscales
            Paragraph texto = new Paragraph(_strNombreEmisor + "\n", ftHeader);
            strCadena.Append(_dirDomicilioFiscal.StrCalle);
            strCadena.Append(" ");
            strCadena.Append(_dirDomicilioFiscal.StrNumeroExterior);
            if (!string.IsNullOrEmpty(_dirDomicilioFiscal.StrNumeroInterior))
            {
                strCadena.Append("-");
                strCadena.Append(_dirDomicilioFiscal.StrNumeroInterior);
            }
            texto.Add(new Paragraph(strCadena.ToString(), ftHeader));
            texto.Add(new Paragraph(_dirDomicilioFiscal.StrColonia, ftHeader));

            strCadena.Remove(0, strCadena.Length);
            strCadena.Append(_dirDomicilioFiscal.StrLocalidad);
            strCadena.Append(", ");
            strCadena.Append(_dirDomicilioFiscal.StrEstado);
            strCadena.Append(", ");
            strCadena.Append(_dirDomicilioFiscal.StrPais);
            texto.Add(new Paragraph(strCadena.ToString(), ftHeader));

            texto.Add(new Paragraph("C.P. " + _dirDomicilioFiscal.StrCP, ftHeader));

            texto.Add(new Paragraph("RFC " + _strRFCEmisor, ftHeader));

            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.VerticalAlignment   = Element.ALIGN_MIDDLE;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader1.AddCell(celda);

            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.VerticalAlignment   = Element.ALIGN_MIDDLE;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader1.AddCell(celda);

            tblHeaderA.AddCell(tblHeader1);

            //Datos Expedición
            float[] ancho_columnas2 = new float[4];
            ancho_columnas2[0] = 100;
            ancho_columnas2[1] = 200;
            ancho_columnas2[3] = 100;
            ancho_columnas2[2] = tblHeaderB.TotalWidth - 400;
            PdfPTable tblHeader2 = new PdfPTable(ancho_columnas2);
            texto = new Paragraph("AT'N:", ftHeaderB);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph(_strContacto, ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph("FECHA:", ftHeaderB);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph(CRutinas.Fecha_DD_MMM_YYYY(_dtFechaCertificado), ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph(string.Empty, ftHeaderB);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph(_strNombreCliente, ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph("REMISIÓN:", ftHeaderB);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            texto = new Paragraph(_strNotaID, ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader2.AddCell(celda);

            tblHeaderB.AddCell(tblHeader2);

            // Cuádricula para los productos

            PdfContentByte cb = writer.DirectContent;

            // x, y, ancho, alto
            cb.Rectangle(30, 600, 550, 15);
            cb.Stroke();

            cb.MoveTo(100, 600);
            cb.LineTo(100, 615);
            cb.Stroke();

            cb.MoveTo(440, 600);
            cb.LineTo(440, 615);
            cb.Stroke();

            cb.MoveTo(520, 600);
            cb.LineTo(520, 615);
            cb.Stroke();

            cb.Rectangle(30, 150, 550, 440);
            cb.Stroke();

            cb.MoveTo(100, 150);
            cb.LineTo(100, 590);
            cb.Stroke();

            cb.MoveTo(440, 150);
            cb.LineTo(440, 590);
            cb.Stroke();

            cb.MoveTo(520, 150);
            cb.LineTo(520, 590);
            cb.Stroke();

            // Encabezados de los productos
            float[] ancho_columnas3 = new float[4];
            ancho_columnas3[0] = 55;
            ancho_columnas3[1] = 345;
            ancho_columnas3[2] = 68;
            ancho_columnas3[3] = 60;
            PdfPTable tblHeader3 = new PdfPTable(ancho_columnas3);
            texto = new Paragraph("CANTIDAD", ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader3.AddCell(celda);

            texto = new Paragraph("DESCRIPCIÓN", ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader3.AddCell(celda);

            texto = new Paragraph("P.UNITARIO", ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader3.AddCell(celda);

            texto = new Paragraph("TOTAL", ftHeader);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.Border = Rectangle.NO_BORDER;
            tblHeader3.AddCell(celda);

            tblHeaderC.AddCell(tblHeader3);
            #endregion


            tblHeaderA.WriteSelectedRows(0, -1, 0, -1,
                                         document.LeftMargin, 760,
                                         writer.DirectContent);

            tblHeaderB.WriteSelectedRows(0, -1, 0, -1,
                                         document.LeftMargin, 670,
                                         writer.DirectContent);

            tblHeaderC.WriteSelectedRows(0, -1, 0, -1,
                                         document.LeftMargin, 617,
                                         writer.DirectContent);

            #region Footer
            PdfPTable tblFooterA = new PdfPTable(1);
            PdfPTable tblFooterB = new PdfPTable(1);
            tblFooterA.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
            tblFooterA.DefaultCell.Border = Rectangle.NO_BORDER;
            tblFooterA.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

            tblFooterB.TotalWidth         = page.Width - document.LeftMargin - document.RightMargin;
            tblFooterB.DefaultCell.Border = Rectangle.NO_BORDER;
            tblFooterB.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;

            float[] ancho_columnasFA = new float[3];
            ancho_columnasFA[0] = 380;
            ancho_columnasFA[1] = 88;
            ancho_columnasFA[2] = 60;
            PdfPTable tblFooter1 = new PdfPTable(ancho_columnasFA);

            texto        = new Paragraph(_strTotalLetras.ToUpper(), ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_LEFT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Rowspan             = 2;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph("SUBTOTAL:", ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph(_amtSubTotal.ToString("c"), ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.BOTTOM_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            if (_amtDescuento > 0)
            {
                texto        = new Paragraph("MONTO CON DESCUENTO:", ftFooter);
                celda        = new PdfPCell(texto);
                celda.Border = Rectangle.NO_BORDER;
                celda.HorizontalAlignment = Element.ALIGN_RIGHT;
                celda.VerticalAlignment   = Element.ALIGN_TOP;
                tblFooter1.AddCell(celda);

                decimal amtConDescuento = _amtSubTotal - _amtDescuento;
                texto        = new Paragraph(amtConDescuento.ToString("c"), ftFooter);
                celda        = new PdfPCell(texto);
                celda.Border = Rectangle.BOTTOM_BORDER;
                celda.HorizontalAlignment = Element.ALIGN_RIGHT;
                celda.VerticalAlignment   = Element.ALIGN_TOP;
                tblFooter1.AddCell(celda);

                texto        = new Paragraph(string.Empty, ftFooter);
                celda        = new PdfPCell(texto);
                celda.Border = Rectangle.NO_BORDER;
                celda.HorizontalAlignment = Element.ALIGN_RIGHT;
                celda.VerticalAlignment   = Element.ALIGN_TOP;
                tblFooter1.AddCell(celda);
            }

            texto        = new Paragraph("IVA " + _amtTasa + "%:", ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph(_amtImpuesto.ToString("c"), ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.BOTTOM_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph(string.Empty, ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph("TOTAL:", ftFooterB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            tblFooter1.AddCell(celda);

            texto = new Paragraph(_amtTotal.ToString("c"), ftFooterB);
            celda = new PdfPCell(texto);
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Border = Rectangle.BOTTOM_BORDER;
            tblFooter1.AddCell(celda);

            texto        = new Paragraph(" \n\n\n ", ftFooter);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_RIGHT;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 3;
            tblFooter1.AddCell(celda);


            tblFooterA.AddCell(tblFooter1);

            float[] ancho_columnasFB = new float[4];
            ancho_columnasFB[0] = 200;
            ancho_columnasFB[1] = 200;
            ancho_columnasFB[2] = 200;
            ancho_columnasFB[3] = 200;
            PdfPTable tblFooter2 = new PdfPTable(ancho_columnasFB);

            texto        = new Paragraph(string.Empty, ftHeaderB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 2;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph(_strVendedor, ftHeader);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph(string.Empty, ftHeaderB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph("CLIENTE", ftHeader);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.TOP_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph(string.Empty, ftHeaderB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph("VENDEDOR", ftHeaderB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.TOP_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            texto        = new Paragraph(string.Empty, ftHeaderB);
            celda        = new PdfPCell(texto);
            celda.Border = Rectangle.NO_BORDER;
            celda.HorizontalAlignment = Element.ALIGN_CENTER;
            celda.VerticalAlignment   = Element.ALIGN_TOP;
            celda.Colspan             = 1;
            tblFooter2.AddCell(celda);

            tblFooterB.AddCell(tblFooter2);

            #endregion

            tblFooterA.WriteSelectedRows(0, -1, 0, -1,
                                         document.LeftMargin, 150,
                                         writer.DirectContent);

            tblFooterB.WriteSelectedRows(0, -1, 0, -1,
                                         document.LeftMargin, 90,
                                         writer.DirectContent);
        }
示例#9
0
 public void DrawLine(PdfContentByte cb, float x1, float x2, float y)
 {
     cb.MoveTo(x1, y);
     cb.LineTo(x2, y);
     cb.Stroke();
 }