Beispiel #1
0
        public string CreatePdfFromImages(ClassificationPdfRequest PdfRequest)
        {
            this.OutputFolder     = ConfigurationManager.AppSettings["OutputFiles"].ToString();
            this.ImagesFolderPath = Path.Combine(OutputFolder, PdfRequest.BatchName, "Images");
            string DestinationPdfFolder = Path.Combine(OutputFolder, PdfRequest.BatchName, "ManualPDF");
            string RandomFileName       = Path.GetRandomFileName() + ".pdf";
            string DestinationPdfFile   = Path.Combine(DestinationPdfFolder, RandomFileName);

            if (!Directory.Exists(DestinationPdfFolder))
            {
                Directory.CreateDirectory(DestinationPdfFolder);
            }

            iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(0, 0, 2481, 3508);
            using (var ms = new MemoryStream())
            {
                var document = new iTextSharp.text.Document(pageSize, 0, 0, 0, 0);
                iTextSharp.text.pdf.PdfWriter.GetInstance(document, ms).SetFullCompression();
                document.Open();
                foreach (string Image in PdfRequest.Images)
                {
                    string SourceImage   = Path.Combine(ImagesFolderPath, Image);
                    var    ImageInstance = iTextSharp.text.Image.GetInstance(SourceImage);
                    ImageInstance.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
                    document.Add(ImageInstance);
                }
                document.Close();
                File.WriteAllBytes(DestinationPdfFile, ms.ToArray());
            }
            //byte[] ms= CreatePdf(ImagesFolderPath);
            return(Path.Combine(PdfRequest.BatchName, "ManualPDF", RandomFileName));
        }
        public HttpResponseMessage CreatePdfFromImages(ClassificationPdfRequest PdfRequest)
        {
            string PdfPath = iClassificationService.CreatePdfFromImages(PdfRequest);

            return(Request.CreateResponse(HttpStatusCode.OK, PdfPath));
        }