Beispiel #1
0
        public JsonResult GetPDFFile(string filePath)
        {
            var ext     = Path.GetExtension(filePath);
            var ftp     = ConfigContext.Current.FtpConfig["package"];
            var ftpPath = filePath.Replace(ftp.Site, "");
            var pdfPath = ftpPath.Replace(ext, ".pdf");

            pdfPath = TempDirectory + "\\" + pdfPath.Replace("/", "\\");
            pdfPath = pdfPath.Replace("\\\\", "\\");

            //判断PDF文件是否存在
            var file = new FileInfo(pdfPath);

            if (!file.Exists)
            {
                //去FTP下载
                using (var client = new FtpHelper(ftp))
                {
                    var srcPath = pdfPath.Replace(".pdf", ext);
                    client.Get(srcPath, ftpPath);

                    //TODO:注释了
                    PDFConverter.Convert(srcPath, pdfPath);
                }
            }


            return(Json2(new HttpResponseResult
            {
                Code = 0,
                Data = "/" + pdfPath.Replace(Server.MapPath("~"), "").Replace("\\", "/")
            }));
        }
Beispiel #2
0
        //تبدیل به پی دی اف (بدلیل عدم داشتن وقت کافی تکمیل نشد) 
        private void toPdf_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                DataGridView v = new DataGridView();

                DataTable dt = new DataTable();
                foreach (DataGridViewColumn col in dgvFactors.Columns)
                {
                    if (col.GetType() == typeof(DataGridViewTextBoxColumn))
                    {
                        dt.Columns.Add(col.HeaderText);
                    }
                }
                foreach (DataGridViewRow row in dgvFactors.Rows)
                {
                    DataRow dRow = dt.NewRow();
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        //if (cell.GetType() == typeof(DataGridViewTextBoxColumn))
                        dRow[cell.ColumnIndex] = cell.Value;
                    }
                    dt.Rows.Add(dRow);
                }
                PDFConverter pdf = new PDFConverter(sfd.FileName, dt);
                pdf.Generate(_factorService.GetFactors());
            }
        }
Beispiel #3
0
        private void converter()
        {
            try
            {
                StringBuilder sb    = new StringBuilder();
                String        texto = PDFConverter.PrintPDFToText(txtPDFfile.Text);

                this.Invoke(new MethodInvoker(delegate()
                {
                    richEditControl1.Document.Text = texto;
                }));


                this.barStaticItemPaginas.Caption = "" + PDFConverter.GetNumberPagesOfPDF(txtPDFfile.Text);
            }
            catch (Exception ex)
            {
                var type = ex.GetType();
                if (ex.Message.Contains("not found as file or resource"))
                {
                    XMessageIts.Advertencia("O arquivo PDF a ser convertido não foi informado ",
                                            "Atenção");
                }
                else
                {
                    XMessageIts.Advertencia("Arquivo PDF informado é inválido");
                }
            }
        }
        protected void Reject_btn_Click(object sender, EventArgs e)
        {
            int rowIndex = ((sender as Button).NamingContainer as GridViewRow).RowIndex;



            string   Path = User_grd.DataKeys[rowIndex].Values[1].ToString();
            string   ID   = User_grd.DataKeys[rowIndex].Values[0].ToString();
            FileInfo info = new FileInfo(Path);

            Path = "~/StaticHTML/" + info.Name.Replace(".pdf", "") + ".html";
            string content = "<div class='row'><span id ='temp' style='float:right; color:violet;text-decoration:bold'> Rejected, " + Session["DepName"].ToString() + " </span><br><img id ='Sign_lbl' src='../Content/signature.jpg' style='width:10%;height:10%;float: right;'></div><br>";

            File.AppendAllText(Server.MapPath(Path), content);
            int Res = PDFConverter.DoConvert(info.Name.Replace(".pdf", ""), Path);

            if (Res == 1)
            {
                UpdateStatusTableAdapter us = new UpdateStatusTableAdapter();
                object  res = us.UpdateStatus(ID, "");
                Boolean chk = Convert.ToBoolean(res);

                if (chk == true)
                {
                    error_lbl.Text = "Application rejected Successfully!!";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
                else
                {
                    error_lbl.Text = "Error, please try again!!";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
            }
        }
Beispiel #5
0
        public ActionResult DownloadHtmlReports(string Action, string Url)
        {
            PDFConverter pdf      = new PDFConverter();
            string       loc      = Server.MapPath("~/");
            string       fileName = pdf.GeneratePdfFromUrl(Action, loc /*ConfigurationManager.AppSettings["LocalRoot"]*/, Url, ConfigurationManager.AppSettings["RemoteRoot"] + "/");

            return(File(fileName, "application/pdf", Action + ".pdf"));;
        }
Beispiel #6
0
        public ActionResult DownloadDoc(int solicitud_id, int prestamo_id, string cedula, int document_id)
        {
            manager = new DocumentManager();
            var          result         = manager.DocumentParseWithVariables(solicitud_id, prestamo_id, cedula, document_id);
            var          documentObject = manager.GetById(document_id);
            string       loc            = Server.MapPath("~/");
            PDFConverter pdf            = new PDFConverter();
            string       fileName       = pdf.GeneratePdfFromString(result, documentObject.Nombre_Documento, /*ConfigurationManager.AppSettings["LocalRoot"]*/ loc, ConfigurationManager.AppSettings["RemoteRoot"]);

            return(File(fileName, "application/pdf", documentObject.Nombre_Documento + ".pdf"));;
        }
Beispiel #7
0
        public override void Save(string FileName, Bitmap picture)
        {
            PDFConverter converter = new PDFConverter();
            converter.PageSizeType = PageSizeMode.A4;

            string extention = (FileName.Substring(FileName.LastIndexOf('.') + 1)).ToString().ToLower();
            string JpegFileName=FileName.Substring(0, (FileName.LastIndexOf('.') + 1)).ToString()+".jpg";
            picture.Save(JpegFileName, ImageFormat.Jpeg);
            converter.CreatePDF(new string[] { JpegFileName }, FileName);
            picture.Dispose();
            //File.Delete(JpegFileName);
        }
Beispiel #8
0
        private static void appendImageToPDF()
        {
            PDFConverter converter = new PDFConverter();

            converter.PageSizeType = PageSizeMode.ImageSize;
            string[] imgFiles = new string[3];
            imgFiles[0] = "input1.png";
            imgFiles[1] = "input2.bmp";
            imgFiles[2] = "input3.jpg";

            string existFile = "output.pdf";

            converter.AppendToPDF(imgFiles, existFile);
        }
Beispiel #9
0
        private static void createPDFtoStream()
        {
            PDFConverter converter = new PDFConverter();

            converter.PageSizeType = PageSizeMode.ImageSize;
            string[] imgFiles = new string[3];
            imgFiles[0] = "input1.png";
            imgFiles[1] = "input2.bmp";
            imgFiles[2] = "input3.jpg";

            FileStream fileStream = new FileStream("output1.pdf", FileMode.Create);

            converter.CreatePDF(imgFiles, fileStream);
        }
Beispiel #10
0
        private static void createPDFfromDisk()
        {
            PDFConverter converter = new PDFConverter();

            converter.PageSizeType = PageSizeMode.A4;
            string[] imgFiles = new string[3];
            imgFiles[0] = "input1.png";
            imgFiles[1] = "input2.bmp";
            imgFiles[2] = "input3.jpg";

            string outFile = "output.pdf";

            converter.CreatePDF(imgFiles, outFile);
        }
Beispiel #11
0
        public override void Save(string FileName, Bitmap picture)
        {
            PDFConverter converter = new PDFConverter();

            converter.PageSizeType = PageSizeMode.A4;

            string extention    = (FileName.Substring(FileName.LastIndexOf('.') + 1)).ToString().ToLower();
            string JpegFileName = FileName.Substring(0, (FileName.LastIndexOf('.') + 1)).ToString() + ".jpg";

            picture.Save(JpegFileName, ImageFormat.Jpeg);
            converter.CreatePDF(new string[] { JpegFileName }, FileName);
            picture.Dispose();
            //File.Delete(JpegFileName);
        }
Beispiel #12
0
        protected void submitapp_btn_Click(object sender, EventArgs e)
        {
            string temp           = app_hfd.Value;
            Random r              = new Random();
            int    randNum        = r.Next(1000000);
            string sixDigitNumber = randNum.ToString("D6");

            using (FileStream fs = new FileStream(Server.MapPath("~/StaticHTML/" + Session["UserLogin"].ToString() + sixDigitNumber + ".html"), FileMode.Create))
            {
                using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
                {
                    w.WriteLine(temp);
                }
            }
            string NamePath = "~/Applications/" + Session["UserLogin"].ToString() + sixDigitNumber + ".pdf";

            int Res = PDFConverter.DoConvert(Session["UserLogin"].ToString() + sixDigitNumber, "~/StaticHTML/" + Session["UserLogin"].ToString() + sixDigitNumber + ".html");

            if (Res == 0)
            {
                error_lbl.Text = "Failed to generate PDF, Try again!!";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
            }
            else
            {
                Boolean Result = InsertApplication(NamePath);
                if (Result == true)
                {
                    error_lbl.Text = "Application forwarded successfully, Refer Application list!!";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
                else
                {
                    error_lbl.Text = "DB Error, Try again!!";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
            }
        }
Beispiel #13
0
        private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // activityIndicator
                UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView();
                activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.White;
                activityIndicator.StartAnimating();
                activityIndicator.HidesWhenStopped = true;
                activityIndicator.Frame            = new RectangleF((this.Frame.Width / 2) - 10, (this.Frame.Height / 2) - 10, 20, 20);
                this.AddSubview(activityIndicator);

                // Generate pdf thumbnail
                Page             page       = null;
                Annotation       annotation = null;
                BackgroundWorker worker     = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    page = BooksOnDeviceAccessor.GetPage(bookID, pageID);

                    if (String.IsNullOrEmpty(text))
                    {
                        annotation = BooksOnDeviceAccessor.GetAnnotation(bookID, pageID);
                    }
                };
                worker.RunWorkerCompleted += delegate
                {
                    this.InvokeOnMainThread(delegate
                    {
                        activityIndicator.StopAnimating();

                        if (page != null)
                        {
                            String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                            if (!String.IsNullOrEmpty(localPath))
                            {
                                CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                                if (pdfDoc != null)
                                {
                                    CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                    if (pdfPage != null)
                                    {
                                        UIImage pdfImg = PDFConverter.Transform2Image(pdfPage, this.Frame.Width);

                                        // pageView
                                        UIImageView pageView = new UIImageView();
                                        pageView.Frame       = new RectangleF(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                        // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (dictionary != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = DrawAnnotation(item.Key, item.Value);

                                                    if (annImg != null)
                                                    {
                                                        // Scale down the annotation image
                                                        annImg = annImg.Scale(new SizeF(pdfImg.Size.Width, pdfImg.Size.Height));

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = Overlap(pdfImg, annImg);
                                                    }
                                                }
                                            }
                                        }

                                        pageView.Image = pdfImg;
                                        this.AddSubview(pageView);

                                        // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                                        SkipBackup2iCloud.SetAttribute(localPath);

                                        // Add ribbon if this is bookmark thumbnail
                                        if (bookmark)
                                        {
                                            UIImageView ribbon = new UIImageView();
                                            ribbon.Image       = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                            ribbon.Frame       = new RectangleF(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                            this.AddSubview(ribbon);
                                        }

                                        // Do not add text if this is annotation thumbnail
                                        if (!String.IsNullOrEmpty(text))
                                        {
                                            // titleLabel
                                            UILabel titleLabel         = new UILabel();
                                            titleLabel.Frame           = new RectangleF(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                            titleLabel.Font            = UIFont.SystemFontOfSize(16f);
                                            titleLabel.BackgroundColor = UIColor.Clear;
                                            titleLabel.TextColor       = eBriefingAppearance.DarkGrayColor;
                                            titleLabel.Lines           = 2;
                                            titleLabel.LineBreakMode   = UILineBreakMode.TailTruncation;
                                            titleLabel.TextAlignment   = UITextAlignment.Center;
                                            titleLabel.Text            = text;
                                            this.AddSubview(titleLabel);
                                        }
                                    }
                                }
                            }
                        }
                    });
                };
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }