Ejemplo n.º 1
0
 public static void getPathList()
 {
     try
     {
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.Load(@"PathFile.xml");
         XmlNode     xn  = xmlDoc.SelectSingleNode("pdflist");
         XmlNodeList xnl = xn.ChildNodes;
         foreach (XmlNode xn1 in xnl)
         {
             PdfModel    model = new PdfModel();
             XmlElement  xe    = (XmlElement)xn1;
             XmlNodeList xnl0  = xe.ChildNodes;
             model.doctype   = int.Parse(xnl0.Item(0).InnerText);
             model.year      = xnl0.Item(1).InnerText;
             model.pdfPath   = xnl0.Item(2).InnerText;
             model.excelPath = xnl0.Item(3).InnerText;
             model.excelHead = xnl0.Item(4).InnerText;
             mappingList.Add(model);
         }
     }
     catch (Exception ex)
     {
         //LogHelper.WriteLog(typeof(PathUtil), ex);
     }
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Html2Pdf([FromBody] PdfModel model)
        {
            try
            {
                if (model.config.scale == 0.0)
                {
                    model.config.scale = 1;
                }

                var payload = JsonConvert.SerializeObject(model.config,
                                                          Newtonsoft.Json.Formatting.Indented,
                                                          new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore
                });

                var pdfPath = await _nodeServices.InvokeAsync <string>("./Node/htmlToPdf.js", model.html, payload);

                var bytes = System.IO.File.ReadAllBytes(pdfPath);
                return(File(bytes, "application/pdf"));
            }
            catch (Exception ex)
            {
                _telemetryClient.TrackException(ex);

                return(BadRequest(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PdfModel = await _context.PdfModels.FindAsync(id);

            if (PdfModel != null)
            {
                _context.PdfModels.Remove(PdfModel);
                await _context.SaveChangesAsync();
            }
            string filePath = Path.Combine(Directory.GetCurrentDirectory(),
                                           "wwwroot",
                                           "File",
                                           PdfModel.ProductName + ".pdf");

            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        public IHttpActionResult PutPdfModel(int id, PdfModel pdfModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pdfModel.VehicleId)
            {
                return(BadRequest());
            }

            db.Entry(pdfModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PdfModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 5
0
        public ActionResult PdfRazor()
        {
            // Get razor from file or from your CMS
            const string razor = "<h1>PDF  3</h1><p>Hello @Model.Field1</p><p>@Model.Field2</p>";

            // Provide model
            var model = new PdfModel
            {
                Field1 = "Jim Panse",
                Field2 = "Foo Bar"
            };

            // Parse PDF from Razor template
            var ms = (new RazorPDF.PdfParser()).ParseRazor(razor, model);

            // Write out PDF to file system
            var content = ms.ToArray();

            using (var fs = System.IO.File.OpenWrite(HttpContext.Server.MapPath("~/App_Data/foobar.pdf")))
            {
                fs.Write(content, 0, (int)content.Length);
            }

            // Return memory stream
            return(this.Pdf(content));

            // Or return file as stream
            return(this.PdfFile(HttpContext.Server.MapPath("~/App_Data/foobar.pdf")));
        }
Ejemplo n.º 6
0
        public IHttpActionResult GetChartData(PdfModel pdfModel)
        {
            var tc    = new TripsController();
            var trips = tc.GetChartData(pdfModel);

            return(Ok(trips));
        }
Ejemplo n.º 7
0
 public MenugroupViewModel()
 {
     ModalModel   = new ModalModel();
     PageModel    = new PageModel();
     PdfModel     = new PdfModel();
     ExtLinkModel = new ExtLinkModel();
 }
Ejemplo n.º 8
0
        public IHttpActionResult GenerateChart(PdfModel selection)
        {
            var carguidesController = new CarguidesController();
            var carTrips            = carguidesController.GetCarByDate(selection.VehicleId, selection.FromDate, selection.ToDate);

            return(Ok(carTrips));
        }
Ejemplo n.º 9
0
        public static void ConvertHtmlStringToPdf(PdfModel model)
        {
            // Render any HTML fragment or document to HTML
            var Renderer = new IronPdf.HtmlToPdf();

            Renderer.PrintOptions.PaperSize        = IronPdf.PdfPrintOptions.PdfPaperSize.A4;
            Renderer.PrintOptions.PaperOrientation = IronPdf.PdfPrintOptions.PdfPaperOrientation.Portrait;
            Renderer.PrintOptions.MarginTop        = 10; //millimeters
            Renderer.PrintOptions.MarginBottom     = 10; //millimeters
            Renderer.PrintOptions.MarginLeft       = 10; //millimeters
            Renderer.PrintOptions.MarginRight      = 10; //millimeters
            Renderer.PrintOptions.CssMediaType     = IronPdf.PdfPrintOptions.PdfCssMediaType.Print;
            Renderer.PrintOptions.Header           = new IronPdf.SimpleHeaderFooter()
            {
                DrawDividerLine = true,
                FontSize        = 16
            };


            string source = model.HtmlString;
            var    pdf    = Renderer.RenderHtmlAsPdf(source);

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

            pdf.SaveAs(model.RepositoryPath);

            // This neat trick opens our PDF file so we can see the result in our default PDF viewer
            // System.Diagnostics.Process.Start(model.RepositoryPath);
        }
 public string StartGeneration(PdfModel model)
 {
     var pdfBuilder = new PdfBuilder();
     var task = pdfBuildr.BuildAsync(model);
     var ticket = Guid.NewGuid().ToString("N");
     _workMap[ticket] = task;
     return ticket;
 }
Ejemplo n.º 11
0
        public void GenerateReport(TourEntry tour, IEnumerable <LogEntry> logs)
        {
            string   filePath = GetReportFolderPath(tour.Name);
            PdfModel model    = QuestPdfDataSource.GetTourAndLogsInfo(tour, logs);
            var      document = new QuestpdfTemplate(model);

            document.GeneratePdf(filePath);
        }
Ejemplo n.º 12
0
        public IHttpActionResult GeneratePdfUrl(PdfModel pdfModel)
        {
            var pdfhelper = new PdfHelper();

            var url = pdfhelper.GetVehicleTripsPdfUrl(pdfModel);

            return(Ok(url));
        }
Ejemplo n.º 13
0
        public string GetVehicleTripsPdfUrl(PdfModel pdfModel)
        {
            var tc    = new TripsController();
            var trips = tc.GetVehicleTrips(pdfModel);

            var url = BuildPdfAndReturnUrl(trips);

            return(url);
        }
Ejemplo n.º 14
0
        public static async Task DownloadDocumentsAsync(PdfModel PdfModel)
        {
            var stream = await PdfService.DownloadFileAsync(PdfModel.Url);

            if (stream == null)
            {
                return;
            }
            await SaveFileAsync(PdfModel.FileName, stream);
        }
Ejemplo n.º 15
0
        public static string GetcarTripsPdfUrl(PdfModel pdfModel)
        {
            var carguidesController = new CarguidesController();
            var vehicleController   = new VehiclesController();
            var carTrips            = carguidesController.GetCarguidesByVehicleId(pdfModel.VehicleId);
            var vehicle             = vehicleController.GetVehicles().FirstOrDefault(x => x.VehicleId == pdfModel.VehicleId);
            var url = buildpdf(carTrips, vehicle, pdfModel.FromDate, pdfModel.ToDate);

            return(url);
        }
Ejemplo n.º 16
0
        public ActionResult SpedizioniConcluse(SpedizioneViewModel viewModel)
        {
            List <SpedizioneViewModel> lista = new List <SpedizioneViewModel>();

            using (DatabaseContext db = new DatabaseContext())
            {
                int token = viewModel.Id;
                if (ModelState.IsValid)
                {
                    // effettuo modifica
                    if (viewModel.LDV != null && Utility.CheckFormatoFile(viewModel.LDV, TipoMedia.TESTO))
                    {
                        CORRIERE_SERVIZIO_SPEDIZIONE spedizione = db.CORRIERE_SERVIZIO_SPEDIZIONE.SingleOrDefault(m => m.ID == viewModel.Id);
                        if (spedizione != null)
                        {
                            var    annuncio      = spedizione.ANNUNCIO_TIPO_SCAMBIO_SPEDIZIONE.FirstOrDefault().ANNUNCIO_TIPO_SCAMBIO.ANNUNCIO;
                            string tokenMittente = annuncio.PERSONA.TOKEN.ToString();
                            if (annuncio.ID_ATTIVITA != null)
                            {
                                tokenMittente = annuncio.ATTIVITA.TOKEN.ToString();
                            }
                            // cambiare percorso di salvataggio
                            FileUploadifive allegatoPdf = UploadFile(viewModel.LDV, TipoUpload.Pdf, tokenMittente);
                            PdfModel        model       = new PdfModel();
                            spedizione.ID_LDV        = model.Add(db, allegatoPdf.Nome);
                            spedizione.DATA_MODIFICA = DateTime.Now;
                            spedizione.STATO         = (int)StatoSpedizione.LDV;
                            // non modifica
                            db.CORRIERE_SERVIZIO_SPEDIZIONE.Attach(spedizione);
                            db.Entry <CORRIERE_SERVIZIO_SPEDIZIONE>(spedizione).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                        else
                        {
                            ViewBag.Message = "Errore nel caricamento dell'LDV! Riprovare più tardi!";
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Inserire LDV da caricare.";
                }
                token = 0;
                lista = db.SPEDIZIONE_CONCLUSA
                        .Where(m => m.ID == token || token <= 0)
                        .Select(m => new SpedizioneViewModel()
                {
                    Id           = m.ID,
                    NomeAnnuncio = m.NOME,
                    Prezzo       = 0,
                    Stato        = Stato.ATTIVO
                }).ToList();
            }
            return(View(lista));
        }
Ejemplo n.º 17
0
        public void SetPdfFileInfoModels()
        {
            FileLogger.SetLog(InfoConstants.CreatingPdfFileInfo);

            Parallel.For(0, TotalPdfCount, index =>
            {
                try
                {
                    var pdf = AllPdfs[index];

                    if (!string.IsNullOrWhiteSpace(pdf))
                    {
                        var fileName  = Path.GetFileName(pdf);
                        var pageCount = GetPdfPageCount(pdf);
                        var pdfModel  = new PdfModel(fileName, pageCount, pdf);

                        ConcurrentPdfFileInfoModels.Enqueue(pdfModel);
                        Interlocked.Increment(ref TotalPdfProcessed);

                        Console.WriteLine(InfoConstants.LogInParallelFor, index, TotalPdfProcessed);
                    }
                }
                catch (Exception ex)
                {
                    ErrorFiles.Enqueue(ErrorPdf);
                }
            });

            // Handle log for corrupted files
            if (ErrorFiles.Count > 0)
            {
                var          msg    = string.Empty;
                const string header = ExceptionConstants.HeaderForCorruptedFiles;

                while (ErrorFiles.TryDequeue(out var errorFile))
                {
                    msg += errorFile + "\n";
                }

                // Remove last new line
                if (msg.Any())
                {
                    msg.Remove(msg.Length - 1);
                }

                FileLogger.SetLog(header + msg);
                ReportGenerator.GenerateErrorLog(msg);
            }

            FileLogger.WriteToFile(string.Format(InfoConstants.PageCountForPdf, TotalPdfProcessed, TotalPdfCount, Percent.ToString("F")));
            FileLogger.SetLog(InfoConstants.CreatingPdfFileInfoDone);

            SetSummary(InfoConstants.Pdf, TotalPdfCount, TotalPdfProcessed);
        }
Ejemplo n.º 18
0
        public IHttpActionResult GetPdfModel(int id)
        {
            PdfModel pdfModel = db.PdfModels.Find(id);

            if (pdfModel == null)
            {
                return(NotFound());
            }

            return(Ok(pdfModel));
        }
Ejemplo n.º 19
0
        public IHttpActionResult PostPdfModel(PdfModel pdfModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PdfModels.Add(pdfModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = pdfModel.VehicleId }, pdfModel));
        }
Ejemplo n.º 20
0
        public ActionResult PostPdf(PdfModel model)
        {
            if (ModelState.IsValid)
            {
                TempData["Uploaded"] = $"Successfully uploaded {model.PdfFile.FileName}";
            }
            else
            {
                TempData["Uploaded"] = "Error";
            }

            return(View("Index"));
        }
Ejemplo n.º 21
0
        public static void ConvertContractHtmlCodeToPdf(PdfModel model)
        {
            HtmlToPdf converter = new HtmlToPdf();

            if (model.HeaderUrl != null)
            {
                // header settings
                converter.Options.DisplayHeader     = true;
                converter.Header.DisplayOnFirstPage = true;
                converter.Header.DisplayOnOddPages  = true;
                converter.Header.DisplayOnEvenPages = true;
                converter.Header.Height             = 70;

                // add some html content to the header
                PdfHtmlSection headerHtml = new PdfHtmlSection(model.HeaderUrl);
                headerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
                headerHtml.AutoFitWidth  = HtmlToPdfPageFitMode.AutoFit;
                converter.Header.Add(headerHtml);
            }

            if (model.FooterUrl != null)
            {
                // footer settings
                converter.Options.DisplayFooter     = true;
                converter.Footer.DisplayOnFirstPage = true;
                converter.Footer.DisplayOnOddPages  = true;
                converter.Footer.DisplayOnEvenPages = true;
                converter.Footer.Height             = 60;

                // add some html content to the footer
                PdfHtmlSection footerHtml = new PdfHtmlSection(model.FooterUrl, "");
                footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
                converter.Footer.Add(footerHtml);

                PdfTextSection text = new PdfTextSection(0, 10, "Page: {page_number} of {total_pages}  ", new System.Drawing.Font("Arial", 8));
                text.HorizontalAlign = PdfTextHorizontalAlign.Right;
                converter.Footer.Add(text);
            }

            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            converter.Options.MarginLeft         = 30;
            converter.Options.MarginRight        = 30;
            converter.Options.MarginTop          = 20;
            converter.Options.MarginBottom       = 25;

            PdfDocument doc = converter.ConvertHtmlString(model.HtmlString);

            doc.Save(model.RepositoryPath);
            doc.Close();
        }
 public ActionResult Put(int id, [FromBody] PdfModel product)
 {
     try
     {
         context.Entry(product).State = EntityState.Modified;
         context.SaveChanges();
         //return CreateAtRoute("GetProduct", new{id=product.id},product );
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Método para exportar para pdf
        /// </summary>
        private void ExportPdf()
        {
            // Expportando para pdf e desabilitando botão
            PdfModel.ExportEstimatePdf(aux);
            btnPdf.IsEnabled = true;

            // Mensagem de sucesso
            MessageBox.Show(
                "PDF fo orçamento gerado",
                "Sucesso",
                MessageBoxButton.OK,
                MessageBoxImage.Information
                );
        }
 public ActionResult Post([FromBody] PdfModel product)
 {
     try
     {
         context.product.Add(product);
         context.SaveChanges();
         //return CreateAtRoute("GetProduct", new { id=product.id },product );
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 25
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            PdfModel = await _context.PdfModels.FirstOrDefaultAsync(m => m.Id == id);

            if (PdfModel == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 26
0
        public ActionResult Handle(PdfModel model)
        {
            //Use NUGET
            //install-package api2pdf

            var a2pClient = new Api2Pdf("YOURAPIKEY");

            var pdfUrl = a2pClient.WkHtmlToPdf.FromHtml(model.Content).Pdf;

            var result = new
            {
                pdfUrl = pdfUrl
            };

            return(Content(JsonConvert.SerializeObject(result), "application/json"));
        }
Ejemplo n.º 27
0
        public static void ConvertHtmlCodeToPdf(PdfModel model)
        {
            HtmlToPdf converter = new HtmlToPdf();

            if (model.HeaderUrl != null)
            {
                // header settings
                converter.Options.DisplayHeader     = true;
                converter.Header.DisplayOnFirstPage = true;
                converter.Header.DisplayOnOddPages  = true;
                converter.Header.DisplayOnEvenPages = true;
                converter.Header.Height             = 70;

                // add some html content to the header
                PdfHtmlSection headerHtml = new PdfHtmlSection(model.HeaderUrl);
                headerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
                headerHtml.AutoFitWidth  = HtmlToPdfPageFitMode.AutoFit;
                converter.Header.Add(headerHtml);
            }

            if (model.FooterUrl != null)
            {
                // footer settings
                converter.Options.DisplayFooter     = true;
                converter.Footer.DisplayOnFirstPage = true;
                converter.Footer.DisplayOnOddPages  = true;
                converter.Footer.DisplayOnEvenPages = true;
                converter.Footer.Height             = 50;

                // add some html content to the footer
                PdfHtmlSection footerHtml = new PdfHtmlSection(model.FooterUrl, "");
                footerHtml.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
                converter.Footer.Add(footerHtml);
            }

            converter.Options.PdfPageSize        = PdfPageSize.A4;
            converter.Options.PdfPageOrientation = PdfPageOrientation.Portrait;
            converter.Options.MarginLeft         = 10;
            converter.Options.MarginRight        = 10;
            converter.Options.MarginTop          = 20;
            converter.Options.MarginBottom       = 20;

            PdfDocument doc = converter.ConvertHtmlString(model.HtmlString, null);

            doc.Save(model.RepositoryPath);
            doc.Close();
        }
Ejemplo n.º 28
0
        public PdfViewerViewModel()
        {
            IsBusy = false;

            _pdfModel = new PdfModel()
            {
                FileName = "demo03.pdf",
                Url      = "http://www.pdfpdf.com/samples/pptdemo2.pdf"
            };

            Device.BeginInvokeOnMainThread(async() =>
            {
                await DownloadPdf();
            }
                                           );

            DownloadPdfCommand = new Command(async() => await DownloadPdf());
        }
Ejemplo n.º 29
0
        public IActionResult Handle([FromBody] PdfModel model)
        {
            //Use NUGET
            //install-package api2pdf

            var a2pClient = new Api2Pdf("YOURAPIKEY");

            var pdfUrl = a2pClient.WkHtmlToPdf.FromHtml(model.Content).Pdf;

            var result = new
            {
                pdfUrl = pdfUrl
            };

            //Uncomment and modify if CORS is required
            //this.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");

            return(Content(JsonConvert.SerializeObject(result), "application/json"));
        }
Ejemplo n.º 30
0
        public string NewSaveCertificatePdf([FromBody] PdfModel model)
        {
            string certificatePath      = HttpContext.Current.Server.MapPath("~/CertificatePDF");
            string fileFullPath         = certificatePath + "\\Certificate" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
            string FinalCertificatePath = ConfigurationManager.AppSettings["CerificatePathBase"] + "/CertificatePDF/Certificate/" + model.VehicleId + ".pdf";;

            try
            {
                if (!Directory.Exists(certificatePath))
                {
                    Directory.CreateDirectory(certificatePath);
                }

                if (!string.IsNullOrEmpty(model.Base64String))
                {
                    byte[] pdfbytes = Convert.FromBase64String(model.Base64String);
                    File.WriteAllBytes(fileFullPath, pdfbytes);
                }
                return(FinalCertificatePath);
            }
            catch (Exception ex) { return(string.Empty); }
        }