예제 #1
0
        //private static ImageFrameRectangle CalculateNewRectangle(Image image)
        //{
        //    var ratio = 251.0/182;
        //    var result = new ImageFrameRectangle();
        //    if (image.Width/image.Height > ratio)
        //    {
        //        result.Width = 251f;
        //        result.Height = 182f*image.Width/251f;
        //    }
        //    else
        //    {
        //        result.Height = 182f;
        //        result.Width = 251f * image.Height / 182;
        //    }
        //    return result;
        //}

        private static ImageFrameRectangle ExpandToBound(ImageFrameRectangle image, ImageFrameRectangle boundingBox)
        {
            double widthScale = 0, heightScale = 0;

            if (image.Width != 0)
            {
                widthScale = (double)boundingBox.Width / (double)image.Width;
            }
            if (image.Height != 0)
            {
                heightScale = (double)boundingBox.Height / (double)image.Height;
            }

            double scale = Math.Min(widthScale, heightScale);

            var result = new ImageFrameRectangle((int)(image.Width * scale),
                                                 (int)(image.Height * scale));

            return(result);
        }
예제 #2
0
        private static PdfPTable GenerateTscPackingSlipFooter(Partner partner, Document document)
        {
            #region new footer

            var footerLabel = new PdfPTable(2)
            {
                WidthPercentage = 100f
            };
            var newWith = new[] { 50f, 50f };
            footerLabel.SetWidths(newWith);
            //--add copy pack 1
            Phrase phrase1;
            var    baseFontTimesRoman = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            var    normalFont         = new Font(baseFontTimesRoman, 10, Font.NORMAL);
            var    boldFont           = new Font(baseFontTimesRoman, 10, Font.BOLD);

            var exampleBound = new ImageFrameRectangle(251, 182);
            if (!string.IsNullOrEmpty(partner.PackcopyBlock1))
            {
                var packCopyPack = Image.GetInstance(partner.PackcopyBlock1);
                //packCopyPack.ScaleAbsolute(251, 182);
                var imageSize1 = new ImageFrameRectangle(packCopyPack.Width, packCopyPack.Height);
                var newRec     = ExpandToBound(imageSize1, exampleBound);//CalculateNewRectangle(packCopyPack);
                //packCopyPack.ScaleAbsolute(newWith1, 182);
                packCopyPack.ScaleAbsolute(newRec.Width, newRec.Height);
                var footerCell = new PdfPCell(packCopyPack)
                {
                    PaddingRight        = 10f,
                    BorderWidth         = 0,
                    VerticalAlignment   = Element.ALIGN_MIDDLE,
                    HorizontalAlignment = Element.ALIGN_CENTER
                };
                footerLabel.AddCell(footerCell);
            }
            else
            {
                if (!string.IsNullOrEmpty(partner.Title1))
                {
                    phrase1 = new Phrase
                    {
                        new Chunk(partner.Title1, boldFont),
                        new Chunk("\n" + partner.Description1, normalFont)
                    };
                    var footerCell = new PdfPCell(phrase1)
                    {
                        PaddingRight = 10f,
                        BorderWidth  = 0
                    };
                    footerLabel.AddCell(footerCell);
                }
                else
                {
                    var footerCell = new PdfPCell(new Phrase())
                    {
                        PaddingRight = 10f,
                        BorderWidth  = 0
                    };
                    footerLabel.AddCell(footerCell);
                }
            }

            //--add copy pack 2
            if (!string.IsNullOrEmpty(partner.PackcopyBlock2))
            {
                var packCopyPack = Image.GetInstance(partner.PackcopyBlock2);
                //var newWith1 = packCopyPack.Width*182/packCopyPack.Height;
                //var newRec = CalculateNewRectangle(packCopyPack);
                //packCopyPack.ScaleAbsolute(newWith1, 182);
                var imageSize1 = new ImageFrameRectangle(packCopyPack.Width, packCopyPack.Height);
                var newRec     = ExpandToBound(imageSize1, exampleBound);//CalculateNewRectangle(packCopyPack);
                packCopyPack.ScaleAbsolute(newRec.Width, newRec.Height);
                var footerCell = new PdfPCell(packCopyPack)
                {
                    PaddingLeft         = 10f,
                    BorderWidth         = 0,
                    VerticalAlignment   = Element.ALIGN_MIDDLE,
                    HorizontalAlignment = Element.ALIGN_CENTER
                };
                footerLabel.AddCell(footerCell);
            }
            else
            {
                if (!string.IsNullOrEmpty(partner.Title2))
                {
                    phrase1 = new Phrase
                    {
                        new Chunk(partner.Title2, boldFont),
                        new Chunk("\n" + partner.Description2, normalFont)
                    };
                    var footerCell = new PdfPCell(phrase1)
                    {
                        PaddingRight = 10f,
                        BorderWidth  = 0
                    };
                    footerLabel.AddCell(footerCell);
                }
                else
                {
                    var footerCell = new PdfPCell(new Phrase())
                    {
                        PaddingRight = 10f,
                        BorderWidth  = 0
                    };
                    footerLabel.AddCell(footerCell);
                }
            }
            footerLabel.TotalWidth = document.Right - document.Left;
            //footerLabel.WriteSelectedRows(0, -1, 5f, footerLabel.TotalHeight + 10f, pdfWriter.DirectContent);

            #endregion

            return(footerLabel);
        }