Beispiel #1
0
        public void PrintLabels(string Path, int pagePerPDF, int labelsPerPage, string excelFile)
        {
            // Get all adresses and order by characters
            // List<string> listAddresses = GetAllAddresses(excelFile).OrderBy(q => q).ToList();

            List <string> listAddresses = GetAllAddresses(excelFile).ToList();

            // postavljanje prve stranice
            int  iPage = 1;
            bool dalje = true;

            do
            {
                // preuzimanje  seta adresa
                List <string> nalepnice = listAddresses.Skip((iPage - 1) * pagePerPDF * labelsPerPage).Take(pagePerPDF * labelsPerPage).ToList();

                if (nalepnice.Count <= 0)
                {
                    dalje = false;
                    break;
                }

                LabelFormatBLL labelFormatBLL = new LabelFormatBLL();
                PdfLabelUtil   pdfItem        = new PdfLabelUtil();
                int            labelId        = 1;
                if (labelFormatBLL.GetLabelFormat(labelId).Id == labelId)
                {
                    Stream      stream = pdfItem.GeneratePdfLabels(nalepnice, labelFormatBLL.GetLabelFormat(labelId), labelId);
                    PdfDocument pdfDoc = new PdfDocument();
                    if (stream != null)
                    {
                        byte[] streamBytes = PdfLabelUtil.ReadFully(stream);
                        File.WriteAllBytes(Path + iPage.ToString().PadLeft(3, '0') + ".pdf", streamBytes);
                    }
                    else
                    {
                        Console.WriteLine("Something is wrong");
                    }
                    LogError.LogText("Something is wrong");
                }
                iPage++;
            } while (dalje);
        }