How to convert xml to json using angular / javascript

 How to convert xml to json using angular / javascript



import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class XmlToJsonService {

  constructor() { }
  xmlToJson(xml) {

    // Create the return object
    var obj = {};

    if (xml.nodeType == 1) { // element
      // do attributes
      if (xml.attributes.length > 0) {
        obj["@attributes"] = {};
        for (var j = 0j < xml.attributes.lengthj++) {
          var attribute = xml.attributes.item(j);
          obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
        }
      }
    } else if (xml.nodeType == 3) { // text
      obj = xml.nodeValue;
    }

    // do children
    if (xml.hasChildNodes()) {
      for (var i = 0i < xml.childNodes.lengthi++) {
        var item = xml.childNodes.item(i);
        var nodeName = item.nodeName;
        if (typeof (obj[nodeName]) == "undefined") {
          obj[nodeName] = this.xmlToJson(item);
        } else {
          if (typeof (obj[nodeName].push) == "undefined") {
            var old = obj[nodeName];
            obj[nodeName] = [];
            obj[nodeName].push(old);
          }
          obj[nodeName].push(this.xmlToJson(item));
        }
      }
    }
    return obj;
  };
}

how to edit or update pdf file using c#

 how to edit or update pdf file using c#


first we need to install plugin of nuget
"Spire.Pdf"




1).Create Model Classes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EncriptionDecription.Models
{
    public class PDFModel
    {
        public HttpPostedFileBase ImageFile { set; get; }
        public int CompanyID { set; get; }
    }
    public class Company{
        public int ID { set; get; }
        public string Name { set; get; }
        public string Url { set; get; }
        public string Logo { set; get; }
    }
}




2).Create Controller 

using EncriptionDecription.Models;
using Spire.Pdf;
using Spire.Pdf.General.Find;
using Spire.Pdf.Graphics;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.Mvc;

namespace EncriptionDecription.Controllers
{
    public class PDFController : Controller
    {
        public List<Company> Companies = new List<Company>();
        public  PDFController()
        {
            Companies.Add(new Company
            {
                ID=1,Name="Tritex",Url="Tritexsolutions.com",Logo="LogoTritex"
            });
            Companies.Add(new Company
            {
                ID = 2,
                Name = "Nextgen",
                Url = "Nextgen.com",
                Logo = "LogoNextgen"
            });
        }

        public ActionResult Index()
        {
            ViewBag.myfile = "";
            TempData["Companies"] = this.Companies;
            return View();
        }

        [HttpPost]
        public ActionResult Index(PDFModel pdfmodel)
        {
            TempData["Companies"] = this.Companies;
            string rootpath= @"C:\Users\rituraj.vaishanav\source\repos\EncriptionDecription\EncriptionDecription\Files\";
            Spire.Pdf.PdfDocument pdfDoc = new Spire.Pdf.PdfDocument();
            pdfDoc.LoadFromFile(rootpath + pdfmodel.ImageFile.FileName);
            var pages = pdfDoc.Pages;
            foreach (PdfPageBase page in pages)
            {
                PdfTextFindCollection CompanyLogo = page.FindText("<CompanyLogo></CompanyLogo>", TextFindParameter.IgnoreCase);
                PdfTextFindCollection CompanyName = page.FindText("<CompanyName></CompanyName>", TextFindParameter.IgnoreCase);
                PdfTextFindCollection pdfsharptext = page.FindText("Evaluation Warning : The document was created with Spire.PDF for .NET.", TextFindParameter.IgnoreCase);
                var company = this.Companies.Find(x => x.ID == pdfmodel.CompanyID);
                String logoText = company.Logo;
                String nameText = company.Url;
                //Creates a brush
                PdfBrush brush = new PdfSolidBrush(Color.DarkBlue);
                //Defines a font
                PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Regular));
                RectangleF rec;
                foreach (PdfTextFind find in CompanyLogo.Finds)
                {
                    rec = find.Bounds;
                    page.Canvas.DrawRectangle(PdfBrushes.White, rec);
                    page.Canvas.DrawString(logoText, font, brush, rec);
                }
                foreach (PdfTextFind find in CompanyName.Finds)
                {
                    rec = find.Bounds;
                    page.Canvas.DrawRectangle(PdfBrushes.White, rec);
                    page.Canvas.DrawString(nameText, font, brush, rec);
                }

                foreach (PdfTextFind find in pdfsharptext.Finds)
                {
                    rec = find.Bounds;
                    page.Canvas.DrawRectangle(PdfBrushes.White, rec);
                    page.Canvas.DrawString("", font, brush, rec);
                }
                //
            }
            var filename = rootpath + "new" + Guid.NewGuid() + ".pdf";
            pdfDoc.SaveToFile(filename);
            ViewBag.myfile = filename;
            return View();
        }
}




3).Create HTML

@using EncriptionDecription.Models;
@{
    ViewBag.Title = "Index";
}

<div class="row">
    <div class="col-md-8 col-md-offset-2">
        @using (Html.BeginForm("Index", "PDF", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <div class="row">
                <div class="col-md-6">
                    <input type="file" name="ImageFile" required />
                </div>
                <div class="col-md-6">
                    <select name="CompanyID">
                        @foreach (var company in (List<Company>)TempData["Companies"])
                        {
                        <option value="@company.ID">@company.Name</option>
                        }
                    </select>
                    <input type="submit" value="Create" class="btn btn-default" />
                </div>
            </div>
            if (ViewBag.myfile != "")
            {
                <a href="@ViewBag.myfile">download file</a>;
            }
        }

    </div>
</div>









How to remove all quick access file from computer in one time

 How to remove all quick access file from computer in one time 




step1:

first at all press "Window+R" then open a Run dialog box and type "explorer" key word and hit enter 

or 

press "Window+E" shortcut key for open explorer


step2:

now you need to go "View Menu" and then select "Options" option it will show "change folder and search option" and click on it 

it will also open open dailog box 


step3:

in folder option dialog box select "General" tap and under "privacy" option check two option 

1).show recently used files in quick access

2).show frequently used folder in quick access



step4:

and then finaly click on "clear" button and then press "apply" and "ok" button 




Featured Post

How to convert xml to json using angular / javascript

 How to convert xml to json using angular / javascript import  {  Injectable  }  from   '@angular/core' ; @ Injectable ({    provide...

Popular Posts