Exemple #1
0
        public byte[] MergeImageToProfile(long adaNo, short pageNum, PdfOffset image1Offset, PdfOffset image2Offset)
        {
            var distributor = _distributorService.GetDSSDistributors(new[] { adaNo }).FirstOrDefault();

            if (distributor == null)
            {
                throw new ABOException(_resourceManager.GetString("ProfileImageMerging.FailedToFindDistributor"));
            }

            var images     = this.GetImageByAdaNo(distributor);
            var profileBin = this.GetDistributorPhysicalProfile(distributor);

            using (var memory = new MemoryStream())
            {
                PdfReader      reader      = new PdfReader(profileBin);
                PdfStamper     stamper     = new PdfStamper(reader, memory);
                PdfContentByte contentByte = stamper.GetOverContent(pageNum);

                if (images[0] != null)
                {
                    var image = iTextSharp.text.Image.GetInstance(images[0].img_streamdata);
                    image.SetAbsolutePosition(image1Offset.X,
                                              reader.GetPageSize(pageNum).Height - image1Offset.Y - image.Height * image1Offset.Scale);

                    image.ScalePercent(image1Offset.Scale * 100);
                    contentByte.AddImage(image);
                }

                if (images[1] != null)
                {
                    var image = iTextSharp.text.Image.GetInstance(images[1].img_streamdata);
                    image.SetAbsolutePosition(image2Offset.X, reader.GetPageSize(pageNum).Height - image2Offset.Y - image.Height * image2Offset.Scale);

                    image.ScalePercent(image2Offset.Scale * 100);
                    contentByte.AddImage(image);
                }

                stamper.Close();

                return(memory.ToArray());
            }
        }
Exemple #2
0
        public ActionResult GetDistIdsPerAdaNo(long adaNo)
        {
            try
            {
                var dist = _distributorService.GetDSSDistributors(new long[] { adaNo });
                if (dist.Count == 1)
                {
                    return(Json(new { Id1 = dist[0].ID1, Id2 = dist[0].ID2 }));
                }

                return(new JsonErrorResult(_resourceManager.GetString("ProfileImageMerging.FailedToFindDistributor"), HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                return(new JsonErrorResult(ex.Message, HttpStatusCode.NotFound));
            }
        }