レーザーエクステンション

13950 ワード

IronPDFはPDFライブラリです.NETと.ネットコア.これは、ほとんどの無料のPDFライブラリであるとして、IronPDFとして公然と商業的なCけん引PDFライブラリです.これは開発のための無料ですが、商用展開のライセンスを取得する必要があります.この明確なライセンスモデルでは、開発者にGNU/AGPLライセンスモデルのインアウトとアウトを学ぶ必要はなく、代わりにプロジェクトにフォーカスすることができます.
IronPDFを有効にします.NETと.ネットコアの開発者は、生成し、マージ、分割、編集、および抽出し、抽出し、PDFファイルのコンテンツを簡単に、C、△、およびVB.ネット.NETコアと.NET Frameworkだけでなく、HTML、ASPX、CSS、JSからのPDFファイルを作成し、イメージファイル.
IronPDFはPDFにHTML経由で包括的なPDF編集と生成機能を持っています.どうやって動くの?よく、ドキュメントのデザインとレイアウトのほとんどは、既存のHTMLやHTML 5の資産を使用することができます.

のためのアイアンPDF機能.ネット.NETコアアプリケーション
いくつかの素晴らしいIronPDF PDFライブラリの機能が含まれます:
  • .NETのPDFライブラリを生成することができますPDF文書からHTML、画像やASPXファイル
  • 中でPDFファイルを読んでいる
  • .NETと.NETコアアプリケーション
  • PDF からのデータとイメージを抽出する

  • を合併しているPDF文書
    PDP を分割する

  • PDF
  • を操作する


  • アイアンPDFの利点
  • アイアンPDF PDFライブラリは
  • をインストールするのは簡単です
  • アイアンPDF.NETライブラリは、迅速かつ簡単にライセンスオプション
  • を持っています
  • IronPDFは、最も外へ出ます.NETのPDFライブラリと最もoutout.NETコアPDFライブラリ
  • あなたが探していたPDFファイルソリューションです.

    IronPDF PDFライブラリのインストール
    でPDFファイルをインストールします.NETまたは.ネットコアはかなり簡単です.次の方法でインストールできます.
    Nugetパッケージマネージャーを使用して、次のコマンドプロンプトに入力します.Install-Package IronPdfVisual StudioのNugetパッケージマネージャーを使用して、次のようにして、プロジェクトメニューから選択管理Nugetパッケージを開き、IronPDFを検索します.

    図1 -皮肉なnugetパッケージ
    PDF拡張モジュールをインストールします.
    IronPDFを使用すると、ASPを使用できます.NET MVCはPDFファイルを返します.以下のコード例を示します.
    以下に示すように、コントローラーが提供できるメソッドの例です.
    C
    public FileResult Generate_PDF_FromHTML_Or_MVC(long id) {
      var objPDF = Renderer.RenderHtmlAsPdf("<h1>IronPdf and MVC Example</h1>"); //Create a PDF Document 
      var objLength = objPDF.BinaryData.Length; //return a pdf document from a view
      Response.AppendHeader("Content-Length", objLength.ToString());
      Response.AppendHeader("Content-Disposition", "inline; filename=PDFDocument_" + id + ".pdf");
      return File(objPDF.BinaryData, "application/pdf;");
    }
    
    VB
    Public Function Generate_PDF_FromHTML_Or_MVC(ByVal id As Long) As FileResult
      Dim objPDF = Renderer.RenderHtmlAsPdf("<h1>IronPdf and MVC Example</h1>") 'Create a PDF Document
      Dim objLength = objPDF.BinaryData.Length 'return a pdf document from a view
      Response.AppendHeader("Content-Length", objLength.ToString())
      Response.AppendHeader("Content-Disposition", "inline; filename=PDFDocument_" & id & ".pdf")
      Return File(objPDF.BinaryData, "application/pdf;")
    End Function
    
    ASPで既存のPDFを提供する例.ネットは続く.
    C
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition","attachment;filename=\"FileName.pdf\"");
    Response.BinaryWrite(System.IO.File.ReadAllBytes("PdfName.pdf"));
    Response.Flush();
    Response.End();
    
    VB
    Response.Clear()
    Response.ContentType = "application/pdf"
    Response.AddHeader("Content-Disposition","attachment;filename=""FileName.pdf""")
    Response.BinaryWrite(System.IO.File.ReadAllBytes("PdfName.pdf"))
    Response.Flush()
    Response.End()
    
    ASPで簡単な例をしましょう.MVCと. NETを使用するNET.NETコア、Visual Studioを開き、新しいASPを作成します.NETコアWebアプリケーション.
    Figure 2 - ASP.Net Core Web Application
    図2 - ASP .NETコアWebアプリケーション
    をクリックします.
    このプロジェクトを作成する場所を選択し、' Create 'をクリックします.
    新しいウィンドウが開き、図3のようになります

    図3 - ASP .NETコアWebアプリケーション
    「Webアプリケーション」を選択します.これは、ASPを作成します.NETコアWebアプリケーション.
    アプリケーションが設定されているので、次のように作成する必要があります.
  • クライアントオブジェクトモデル
  • クライアントサービス
  • ページ
  • を加えます
    PDF文書をダウンロードする
  • 機能性

    MVCモデルを作成する
    モデルを作成するには、次の手順を使用します.
    モデルフォルダを右クリックします

    図4 -モデルフォルダ
    「クラスを追加」を選択します.以下の図5は、' example plodel 'を追加したモデルを示します

    図5 -モデル追加
    たとえば、モデルにコンテンツを追加できます.
    C
    namespace ASPCore_Ex.Models
    {
        public class ExampleModel
        {
            public string Name { get; set; }
            public string Surname { get; set; }
            public int Age { get; set; }
        }
    }
    
    VB
    Namespace ASPCore_Ex.Models
        Public Class ExampleModel
            Public Property Name() As String
            Public Property Surname() As String
            Public Property Age() As Integer
        End Class
    End Namespace
    

    MVCサービスの作成
    次のいくつかの手順に従ってプロジェクトフォルダに必要なサービスを右クリックし、[新しいフォルダを追加]を選択します

    図6 -サービスフォルダ
    「サービス」フォルダを右クリックし、新しいクラスを追加する

    図7 -サービスクラスの追加
    モデルとサービスを次のコードと接続します.
    C
    public class ExampleService
    {
        private static ExampleModel eModel;
        public static void AddExample(ExampleModel exModel)
        {
             eModel = exModel;
        }
        public static ExampleModel GetExample()
        {
             return eModel;
        }
    }
    
    VB
    Public Class ExampleService
        Private Shared eModel As ExampleModel
        Public Shared Sub AddExample(ByVal exModel As ExampleModel)
             eModel = exModel
        End Sub
        Public Shared Function GetExample() As ExampleModel
             Return eModel
        End Function
    End Class
    

    MVCコントローラの追加
    コントローラを追加するには、次の手順または2つの手順を右クリックして

    図8 -追加コントローラ
    コントローラの選択

    図9 -コントローラの追加
    次の画像は、追加されるコントローラの例を示します.

    図10 -コントローラの例
    コントローラが追加されたら、Controllerクラスのコンストラクターを右クリックし、' Add View 'を選択します.これは、追加するには、かみそりの表示オプションを選択することができますダイアログを開きます.インデックスが既に存在するので、あなたは本当にこのステップに従う必要はありません.ホームフォルダのCSHTMLページ.別のフォルダにインデックスファイルを配置する場合は、新しいビューを追加できます.

    図11 -ビューの追加
    「追加」をクリックします.
    次に、次の画面で、名前を指定し

    図12 -インデックス.京大理
    簡単なフォームをホームページに追加できます
    C
    @model ASPCore_Ex.Models.ExampleModel
    @{
        ViewBag.Title = "Example Index View";
    }
    <h2>Index</h2>
    @using (Html.BeginForm())
    {
        <div class="form-horizontal">
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="form-group">
                @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Surname, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Surname, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Surname, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Age, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Age, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Age, "", new { @class = "text-danger" })
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-10 pull-right">
                    <button type="submit" value="Save" class="btn btn-sm">
                        <i class="fa fa-plus"></i>
                        <span>
                            Save
                        </span>
                    </button>
                </div>
            </div>
        </div>
    }
    
    VB
    <HttpPost>
    Public Function ExampleView(ByVal model As ExampleModel) As ActionResult
      IronPdf.Installation.TempFolderPath = $"{_host.ContentRootPath}/irontemp/"
      IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True
      Dim html = Me.RenderViewAsync("_Example", model)
      Dim ironPdfRender = New IronPdf.ChromePdfRenderer()
      Dim pdfDoc = ironPdfRender.RenderHtmlAsPdf(html.Result)
      Return File(pdfDoc.Stream.ToArray(), "application/pdf")
    End Function
    
    RenderViewAsyncコードは次のようになります.
    C
    public static class ControllerPDF
    {
      public static async Task<string> RenderViewAsync<TModel>(this Controller, string viewName, TModel model, bool partial = false)
      {
        if (string.IsNullOrEmpty(viewName))
        {
          viewName = controller.ControllerContext.ActionDescriptor.ActionName;
        }
        controller.ViewData.Model = model;
        using (var writer = new StringWriter())
        {
          IViewEngine viewEngine = controller.HttpContext.RequestServices.GetService(typeof(ICompositeViewEngine)) as ICompositeViewEngine;
          ViewEngineResult viewResult = viewEngine.FindView(controller.ControllerContext, viewName, !partial);
          if (viewResult.Success == false)
          {
            return $"A view with the name {viewName} could not be found";
          }
          ViewContext viewContext = new ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, writer, new HtmlHelperOptions());
          await viewResult.View.RenderAsync(viewContext);
          return writer.GetStringBuilder().ToString();
        }
      }
    }
    
    VB
    Public Module ControllerPDF
    'INSTANT VB TODO TASK: The following line could not be converted:
      public static async Task(Of String) RenderViewAsync(Of TModel)(Me Controller, String viewName, TModel model, Boolean partial = False)
      If True Then
        If String.IsNullOrEmpty(viewName) Then
          viewName = controller.ControllerContext.ActionDescriptor.ActionName
        End If
        controller.ViewData.Model = model
        Using writer = New StringWriter()
          Dim viewEngine As IViewEngine = TryCast(controller.HttpContext.RequestServices.GetService(GetType(ICompositeViewEngine)), ICompositeViewEngine)
          Dim viewResult As ViewEngineResult = viewEngine.FindView(controller.ControllerContext, viewName, Not partial)
          If viewResult.Success = False Then
            Return $"A view with the name {viewName} could not be found"
          End If
          Dim viewContext As New ViewContext(controller.ControllerContext, viewResult.View, controller.ViewData, controller.TempData, writer, New HtmlHelperOptions())
          Await viewResult.View.RenderAsync(viewContext)
          Return writer.GetStringBuilder().ToString()
        End Using
      End If
    End Module