public string CreateFileWithLabels(IList <PrintLabelInfo> labels,
                                           IList <string> scanFormImages,
                                           BatchInfoToPrint batchInfo,
                                           string outputDirectory,
                                           string name = null)
        {
            var fileName = String.Format("label_{0}.zip",
                                         StringHelper.JoinTwo("_",
                                                              (batchInfo != null && batchInfo.BatchId > 0) ? batchInfo.BatchId.ToString() : null,
                                                              DateHelper.GetAppNowTime().ToString("MM_dd_yyyy_HH_mm_ss")));

            var localPath = outputDirectory + "\\LabelPdf\\" + fileName;

            Directory.CreateDirectory(Path.GetDirectoryName(localPath));

            var labelFiles = labels.Select(f => new ZipFileInfo()
            {
                SourceFilepath    = f.Image,
                InArchiveFilename = f.OrderId + Path.GetExtension(f.Image)
            }).ToArray();

            FileHelper.ZipTo(localPath, labelFiles);

            return("~\\LabelPdf\\" + fileName);
        }
Example #2
0
        public string CreateFileWithLabels(IList <PrintLabelInfo> labels,
                                           IList <string> scanFormImages,
                                           BatchInfoToPrint batchInfo,
                                           string outputDirectory,
                                           string name = null)
        {
            var fileName = String.Format("label_{0}.zpl", DateHelper.GetAppNowTime().ToString("MM_dd_yyyy_HH_mm_ss"));

            var localPath = outputDirectory + "\\LabelPdf\\" + fileName;

            Directory.CreateDirectory(Path.GetDirectoryName(localPath));

            try
            {
                using (var stream = File.Create(localPath))
                {
                    using (var writer = new StreamWriter(stream))
                    {
                        writer.Write("");

                        //if (scanFormImages != null)
                        //{
                        //    foreach (var scanFormImage in scanFormImages)
                        //    {
                        //        if (File.Exists(scanFormImage))
                        //        {
                        //            AddScanForm(writer, scanFormImage);
                        //        }
                        //    }
                        //}

                        var index = 0;
                        while (index < labels.Count)
                        {
                            if (labels[index].IsPdf &&
                                labels[index].SpecialType != LabelSpecialType.MailPickList &&
                                labels[index].ShippingMethodId != ShippingUtils.AmazonPriorityFlatShippingMethodId)
                            //NOTE: Temporary exclude Stamps Priority Flat labels, Amazon return it in pdf format
                            {
                                AddPdfLabel(writer, labels[index]);
                                index++;
                            }
                            else
                            {
                                AddImageLabel(writer, labels[index]);
                                index++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("AddPage", ex);
            }

            return("~\\LabelPdf\\" + fileName);
        }
Example #3
0
        public string CreateFileWithLabels(IList <PrintLabelInfo> labels,
                                           IList <string> scanFormImages,
                                           BatchInfoToPrint batchInfo,
                                           string outputDirectory,
                                           string name = null)
        {
            var      docSize = new iTextSharp.text.Rectangle(288, 432);
            Document doc     = new Document(docSize, 0, 0, 0, 0);

            var fileName = String.Format("label_{0}.pdf",
                                         StringHelper.JoinTwo("_",
                                                              (batchInfo != null && batchInfo.BatchId > 0) ? batchInfo.BatchId.ToString() : null,
                                                              DateHelper.GetAppNowTime().ToString("MM_dd_yyyy_HH_mm_ss")));

            var localPath = outputDirectory + "\\LabelPdf\\" + fileName;

            Directory.CreateDirectory(Path.GetDirectoryName(localPath));

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(localPath, FileMode.Create));

            writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
            writer.CompressionLevel = PdfStream.BEST_COMPRESSION; //TODO: BEST_COMPRESSION

            labels = labels.Where(l => !String.IsNullOrEmpty(l.Image)).ToList();

            doc.Open();

            try
            {
                var index = 0;
                while (index < labels.Count)
                {
                    AddPageWithFullLabel(doc, writer, labels[index]);
                    index++;
                }
            }
            catch (Exception ex)
            {
                _log.Error("AddPage", ex);
            }
            finally
            {
                doc.Close();
            }

            return("~\\LabelPdf\\" + fileName);
        }
        public string CreateFileWithLabels(IList <PrintLabelInfo> labels,
                                           IList <string> scanFormImages,
                                           BatchInfoToPrint batchInfo,
                                           string outputDirectory,
                                           string name = null)
        {
            Document doc = new Document(PageSize.LETTER, 0, 0, 0, 0);

            var fileName = String.Format("label_{0}.pdf",
                                         StringHelper.JoinTwo("_",
                                                              (batchInfo != null && batchInfo.BatchId > 0) ? batchInfo.BatchId.ToString() : null,
                                                              DateHelper.GetAppNowTime().ToString("MM_dd_yyyy_HH_mm_ss")));

            var localPath = outputDirectory + "\\LabelPdf\\" + fileName;

            Directory.CreateDirectory(Path.GetDirectoryName(localPath));

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(localPath, FileMode.Create));

            writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
            writer.CompressionLevel = PdfStream.BEST_COMPRESSION; //TODO: BEST_COMPRESSION

            doc.Open();

            try
            {
                if (batchInfo != null)
                {
                    AddBatchInfo(doc, writer, batchInfo);
                }

                if (scanFormImages != null)
                {
                    foreach (var scanFormImage in scanFormImages)
                    {
                        if (File.Exists(scanFormImage))
                        {
                            AddScanForm(doc, writer, scanFormImage);
                        }
                    }
                }

                var index = 0;
                while (index < labels.Count)
                {
                    if (labels[index].IsPdf &&
                        labels[index].SpecialType != LabelSpecialType.MailPickList &&
                        labels[index].ShippingMethodId != ShippingUtils.AmazonPriorityFlatShippingMethodId && //NOTE: Temporary exclude Stamps Priority Flat labels, Amazon return it in pdf format
                        labels[index].ShippingMethodId != ShippingUtils.AmazonFedExHomeDeliveryShippingMethodId &&
                        labels[index].ShippingMethodId != ShippingUtils.AmazonFedExHomeDeliveryShippingMethodId &&
                        labels[index].ShippingMethodId != ShippingUtils.AmazonFedEx2DayOneRateEnvelopeShippingMethodId &&
                        labels[index].ShippingMethodId != ShippingUtils.AmazonFedEx2DayOneRatePakShippingMethodId)
                    {
                        AddPdfLabel(doc, writer, labels[index]);
                        index++;
                    }
                    else
                    {
                        if (labels[index].LabelSize == PrintLabelSizeType.FullPage)
                        {
                            AddPageWithFullLabel(doc, writer, labels[index]);
                            index++;
                        }
                        else
                        {
                            if (index + 1 < labels.Count)
                            {
                                //Checking next label size
                                if (labels[index + 1].LabelSize == PrintLabelSizeType.FullPage ||
                                    (labels[index + 1].IsPdf &&
                                     labels[index + 1].ShippingMethodId != ShippingUtils.AmazonPriorityFlatShippingMethodId &&
                                     labels[index].ShippingMethodId != ShippingUtils.AmazonFedExHomeDeliveryShippingMethodId &&
                                     labels[index].ShippingMethodId != ShippingUtils.AmazonFedExHomeDeliveryShippingMethodId &&
                                     labels[index].ShippingMethodId != ShippingUtils.AmazonFedEx2DayOneRateEnvelopeShippingMethodId &&
                                     labels[index].ShippingMethodId != ShippingUtils.AmazonFedEx2DayOneRatePakShippingMethodId &&
                                     labels[index + 1].SpecialType != LabelSpecialType.MailPickList))
                                {
                                    AddPageWithTwoHalfLabels(doc, writer, labels[index], null);
                                    index++;
                                }
                                else
                                {
                                    AddPageWithTwoHalfLabels(doc, writer, labels[index], labels[index + 1]);
                                    index += 2;
                                }
                            }
                            else
                            {
                                AddPageWithTwoHalfLabels(doc, writer, labels[index], null);
                                index++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("AddPage", ex);
            }
            finally
            {
                doc.Close();
            }

            return("~\\LabelPdf\\" + fileName);
        }
        private PointF AddBatchInfo(Document doc, PdfWriter writer, BatchInfoToPrint batch)
        {
            doc.NewPage();
            //content.SaveGraphicsState();
            ////content.TranslateScaleRotate(8.5 / 2, 11 / (double)2, 1.0, Math.PI / 2);
            try
            {
                PointF basePoint = new PointF(0, 0);
                basePoint = new PointF(doc.PageSize.Width / 2, doc.PageSize.Height * 1 / (float)2);

                var lineHeight  = 30;
                var basePointDy = 150;

                DrawText(writer,
                         "Labels",
                         BigFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 6 * lineHeight
                         + 10, //Page Caption
                         false);

                DrawText(writer,
                         "Date: " + DateHelper.ToDateTimeString(batch.Date),
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 5 * lineHeight,
                         false);

                DrawText(writer,
                         "Batch ID: " + batch.BatchId,
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 4 * lineHeight,
                         false);

                DrawText(writer,
                         "Batch Name: " + batch.BatchName,
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 3 * lineHeight,
                         false);

                DrawText(writer,
                         "Number of Packages: " + batch.NumberOfPackages,
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 2 * lineHeight,
                         false);

                DrawText(writer,
                         "FIMS AirBill Number: " + StringHelper.GetFirstNotEmpty(batch.FIMSAirBillNumber, "-"),
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy + 1 * lineHeight,
                         false);

                var carriersText = batch.Carriers != null?String.Join(", ", batch.Carriers.Select(c => c.Key + ": " + c.Value)) : "";

                DrawText(writer,
                         "Carriers: " + carriersText,
                         BigNormalFontSize,
                         TextColor,
                         basePoint.X - 200,
                         basePoint.Y + basePointDy,
                         false);

                var index = 11;
                lineHeight = 20;
                if (batch.StyleChanges != null &&
                    batch.StyleChanges.Count > 0)
                {
                    index = index + 2;
                    if (index > 30)
                    {
                        doc.NewPage();
                        index = 0;
                    }

                    DrawText(writer,
                             "Items changed:",
                             FontSize,
                             TextColor,
                             basePoint.X - 200,
                             basePoint.Y + 300 - index * lineHeight,
                             false);

                    foreach (var styleChange in batch.StyleChanges)
                    {
                        index++;
                        if (index > 30)
                        {
                            doc.NewPage();
                            index = 0;
                        }
                        var pointY = basePoint.Y + 300 - index * lineHeight;
                        DrawText(writer,
                                 styleChange.SourceStyleString + " - Size: " + styleChange.SourceStyleSize
                                 + " => " + styleChange.DestStyleString + " - Size: " + styleChange.DestStyleSize,
                                 FontSize,
                                 TextColor,
                                 basePoint.X - 200,
                                 pointY,
                                 false);
                    }
                }


                if (batch.OrdersWithPrintError != null &&
                    batch.OrdersWithPrintError.Count > 0)
                {
                    index = index + 2;
                    if (index > 30)
                    {
                        doc.NewPage();
                        index = 0;
                    }

                    DrawText(writer,
                             "Orders removed because of errors:",
                             FontSize,
                             TextColor,
                             basePoint.X - 200,
                             basePoint.Y + 300 - index * lineHeight,
                             false);

                    foreach (var order in batch.OrdersWithPrintError)
                    {
                        index++;
                        if (index > 30)
                        {
                            doc.NewPage();
                            index = 0;
                        }
                        var pointY = basePoint.Y + 300 - index * lineHeight;
                        DrawText(writer,
                                 "Order " + order.OrderAmazonId + " label #" + order.NumberInBatch,
                                 FontSize,
                                 TextColor,
                                 basePoint.X - 200,
                                 pointY,
                                 false);

                        for (int i = 0; i < order.Items.Count; i++)
                        {
                            index++;
                            if (index > 30)
                            {
                                doc.NewPage();
                                index = 0;
                            }

                            pointY = basePoint.Y + 300 - index * lineHeight;
                            DrawText(writer,
                                     (i + 1) + ". " + order.Items[i].SKU + " - " + order.Items[i].Size + "  " + order.Items[i].Quantity + " pieces  " + order.Items[i].SortIsle + "/" + order.Items[i].SortSection + "/" + order.Items[i].SortShelf,
                                     FontSize,
                                     TextColor,
                                     basePoint.X - 180,
                                     pointY,
                                     false);
                        }
                    }
                }

                if (batch.OrdersWasManuallyRemoved != null &&
                    batch.OrdersWasManuallyRemoved.Count > 0)
                {
                    index = index + 2;
                    if (index > 30)
                    {
                        doc.NewPage();
                        index = 0;
                    }

                    DrawText(writer,
                             "Merchandise removed manually after pick list created",
                             FontSize,
                             TextColor,
                             basePoint.X - 200,
                             basePoint.Y + 300 - index * lineHeight,
                             false);

                    foreach (var order in batch.OrdersWasManuallyRemoved)
                    {
                        index++;
                        if (index > 30)
                        {
                            doc.NewPage();
                            index = 0;
                        }
                        var pointY = basePoint.Y + 300 - index * lineHeight;
                        DrawText(writer,
                                 "Order " + order.OrderAmazonId, // + " label #" + order.NumberInBatch,
                                 FontSize,
                                 TextColor,
                                 basePoint.X - 200,
                                 pointY,
                                 false);

                        for (int i = 0; i < order.Items.Count; i++)
                        {
                            index++;
                            if (index > 30)
                            {
                                doc.NewPage();
                                index = 0;
                            }

                            pointY = basePoint.Y + 300 - index * lineHeight;
                            DrawText(writer,
                                     (i + 1) + ". " + order.Items[i].SKU + " - " + order.Items[i].Size + "  " + order.Items[i].Quantity + " pieces  " + order.Items[i].SortIsle + "/" + order.Items[i].SortSection + "/" + order.Items[i].SortShelf,
                                     FontSize,
                                     TextColor,
                                     basePoint.X - 180,
                                     pointY,
                                     false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Info("Pdf draw batch info (batch: " + batch.BatchName + " - " + batch.BatchId + ")", ex);
            }
            return(new PointF(doc.PageSize.Width - 2 * LabelPaddingX,
                              doc.PageSize.Height / 2 - 2 * LabelPaddingY));
        }