Ejemplo n.º 1
0
        void DrukujKoperty()
        {
            XFont  font       = new XFont("Times", 11, XFontStyle.Bold);
            XFont  fontNormal = new XFont("Arial", 8, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode));
            int    posX       = 30;
            int    posXC      = 250;
            int    offsetY    = 10;
            int    posXoplata = 450;
            string data       = dateTimePicker1.Value.Date.ToString("yyyy-MM-dd");

            string[]    lineour  = new string[6];
            string[]    linecust = new string[6];
            string      file     = "parametry.xml";
            string      filename = "";
            Print       pdf      = new Print();
            PdfDocument document = new PdfDocument();
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.Load(file);
            XmlNodeList nodeList = xmlDoc.SelectNodes("/Parametry/Firma/Wartosc");
            int         l        = 0;

            foreach (XmlNode _node in nodeList)
            {
                lineour[l] = _node.InnerText.ToString(); //Kolejne linie nazwy naszej firmy z xml
                l          = l + 1;
            }
            var page = new PdfPage
            {
                Size        = PageSize.A5,
                Orientation = PageOrientation.Landscape,
                Rotate      = 0
            };
            int nrkoperty = 1;

            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                if (Convert.ToBoolean(dataGridView2.Rows[i].Cells[0].Value))
                {
                    int posY       = 30;
                    int posYC      = 250;
                    int posYoffset = 30;
                    int posYoplata = 30;

                    string nazwa     = dataGridView2[1, i].Value.ToString();
                    string ulica     = dataGridView2[2, i].Value.ToString();
                    string InnyAdres = "";
                    ulica = ulica + " " + dataGridView2[3, i].Value.ToString();
                    string miasto = dataGridView2[4, i].Value.ToString();
                    miasto = miasto + " " + dataGridView2[5, i].Value.ToString();
                    if (dataGridView2[6, i].Value.ToString().Length > 2)
                    {
                        InnyAdres = dataGridView2[6, i].Value.ToString();
                        ulica     = InnyAdres;
                        miasto    = "";
                    }
                    page             = document.AddPage();
                    page.Size        = PageSize.A5;
                    page.Orientation = PageOrientation.Landscape;
                    page.Rotate      = 0;
                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    int       c   = lineour.Count();
                    //---------wydruk nasze dane-------------------
                    for (int count = 0; count < 5; count++)
                    {
                        gfx.DrawString(lineour[count], font, XBrushes.Black, new XRect(posX, posY, 190, 35), XStringFormat.TopLeft);
                        posY = posY + offsetY;
                    }
                    //--------numeracja kopert---------------------
                    gfx.DrawString(nrkoperty.ToString(), fontNormal, XBrushes.Black, new XRect(posX, posY, 190, 35), XStringFormat.TopLeft);
                    nrkoperty = ++nrkoperty;
                    //---------wydruk danych kontrahenta-----------
                    //-------------------------------------------
                    StringBuilder completedWord = new StringBuilder();
                    int           znaki         = nazwa.Count();
                    if (znaki > 40)
                    {
                        List <string> lines         = nazwa.SplitOn(40);//Jeżeli za długa nazwa kontrahenta, to po 40 znaku, przy uwzględnieniu wyrazów, podzielic na 2 linie
                        XRect         adresat1linia = new XRect(posXC + 70, posYC - 10, 120, 20);
                        XRect         adresat2linia = new XRect(posXC + 70, posYC, 120, 20);
                        gfx.DrawString(lines[0], font, XBrushes.Black, adresat1linia, XStringFormats.TopCenter);
                        gfx.DrawString(lines[1], font, XBrushes.Black, adresat2linia, XStringFormats.TopCenter);
                    }
                    else
                    {
                        gfx.DrawString(nazwa, font, XBrushes.Black, new XRect(posXC, posYC, 190, 35), XStringFormat.TopCenter);
                    }
                    //-------------------------------------------
                    posYC = posYC + offsetY;
                    gfx.DrawString(ulica, font, XBrushes.Black, new XRect(posXC, posYC, 190, 35), XStringFormat.TopCenter);
                    posYC = posYC + offsetY;
                    gfx.DrawString(miasto, font, XBrushes.Black, new XRect(posXC, posYC, 190, 35), XStringFormat.TopCenter);
                    posYC = posYC + offsetY;
                    posYC = posYC + offsetY;
                    //----------nadruk oplata pobrana------------
                    gfx.DrawString("OPŁATA POBRANA", font, XBrushes.Black, new XRect(posXoplata, posYoplata, 120, 35), XStringFormat.TopCenter);
                    posYoplata = posYoplata + offsetY;
                    gfx.DrawString("TAXE PERÇUE - POLOGNE", font, XBrushes.Black, new XRect(posXoplata, posYoplata, 120, 35), XStringFormat.TopCenter);
                    posYoplata = posYoplata + offsetY;
                    gfx.DrawString("Umowa z Pocztą Polską S.A ID 337248/B", fontNormal, XBrushes.Black, new XRect(posXoplata, posYoplata, 120, 35), XStringFormat.TopCenter);
                    posYoplata = posYoplata + offsetY;
                }
            }
            int f = 1;

            filename = AppDomain.CurrentDomain.BaseDirectory + @"\pdf\Koperta_" + data + ".pdf";
            while (File.Exists(filename))
            {
                filename = AppDomain.CurrentDomain.BaseDirectory + @"\pdf\Koperta_" + data + "_" + f + ".pdf"; f++;
            }
            document.Save(filename);
            Process.Start(filename);
        }
Ejemplo n.º 2
0
        void DrukujKsiazke()
        {
            string      data     = dateTimePicker2.Value.Date.ToString("yyyy-MM-dd");
            PdfDocument document = new PdfDocument();
            var         page     = new PdfPage();
            Print       ksiazka  = new Print();

            page             = document.AddPage();
            page.Size        = PageSize.A4;
            page.Orientation = PageOrientation.Landscape;
            page.Rotate      = 0;

            int    posYoffset = 80;
            double EndPage    = page.Height - 150;
            int    lp         = 1;

            ksiazka.RysujKsiazke(page, data);
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                if (Convert.ToBoolean(dataGridView2.Rows[i].Cells[0].Value))  //jezeli zaznaczony
                {
                    string nazwa  = dataGridView2[1, i].Value.ToString();
                    string ulica  = dataGridView2[2, i].Value.ToString();
                    string nrdomu = dataGridView2[3, i].Value.ToString();
                    string kod    = dataGridView2[4, i].Value.ToString();
                    string miasto = dataGridView2[5, i].Value.ToString();
                    if (dataGridView2[6, i].Value.ToString().Length > 2)
                    {
                        string InnyAdres = dataGridView2[6, i].Value.ToString();
                        ulica  = InnyAdres;
                        miasto = "";
                        kod    = "";
                    }
                    string faktura = "";
                    if (!string.IsNullOrEmpty(dataGridView2.Rows[i].Cells[7].Value as string))
                    {
                        faktura = dataGridView2[7, i].Value.ToString();
                    }
                    if (posYoffset > EndPage)
                    {
                        page             = document.AddPage();
                        posYoffset       = -20;
                        page.Size        = PageSize.A4;
                        page.Orientation = PageOrientation.Landscape;
                        page.Rotate      = 0;
                    }
                    ksiazka.RysujKsiazkePozycje(page, lp, nazwa, ulica + " " + nrdomu + ", " + kod + " " + miasto, faktura, posYoffset);
                    posYoffset = posYoffset + 20;
                    lp         = ++lp;
                }
            }
            ksiazka.Stopka(page);
            int    f        = 1;
            string filename = AppDomain.CurrentDomain.BaseDirectory + @"\pdf\Ksiazka_" + data + ".pdf";

            while (File.Exists(filename))
            {
                filename = AppDomain.CurrentDomain.BaseDirectory + @"\pdf\ksiazka_" + data + "_" + f + ".pdf"; f++;
            }

            document.Save(filename);
            Process.Start(filename);
        }