在VB.NET和C#中建立PDF — IronPDF教程

This article was translated from English: Does it need improvement?
Translated
View the article in English

本教程將逐步指導您如何在VB.NET中建立和編輯PDF文件。 此技術同樣適用於ASP.NET網頁應用程式控制台應用程式Windows服務桌面程式。 我們將使用VB.NET來建立針對.NET Framework 4或.NET Core 2的PDF專案。您只需一個Visual Basic .NET開發環境,例如Microsoft Visual Studio Community。

快速入門:在VB.NET中建立您的第一個PDF

開始使用IronPDF,通過僅僅兩行程式碼在VB.NET中建立您的第一個PDF。 此快速入門指南演示了IronPDF如何輕鬆地整合到您的.NET應用程式中,使您能夠快速生成PDF文件。 使用IronPDF,您可以輕鬆地將HTML內容轉換為專業品質的PDF文件。 請遵循此簡單範例,看看您可以多快生成您的第一個PDF,並探索IronPDF為您的項目提供的靈活功能。

  1. 使用NuGet套件管理器安裝https://www.nuget.org/packages/IronPdf

    PM > Install-Package IronPdf
  2. 複製並運行這段程式碼片段。

    Dim PDF As New IronPdf.PdfDocument() 
    PDF.SaveAs("output.pdf")
  3. 部署以在您的實時環境中測試

    今天就開始在您的專案中使用IronPDF,透過免費試用

    arrow pointer

最小工作流程(5個步驟)

  1. 下載VB.NET PDF程式庫
  2. 使用VB.NET程式庫建立PDF檔案
  3. 自定義您的PDF檔案樣式
  4. 選擇建立動態內容的方法
  5. 從VB.NET程式庫中編輯您的PDF文件

使用IronPDF在VB .NET中建立和編輯PDF的程式碼

使用VB.NET將HTML渲染為PDF,應用樣式,利用動態內容,並輕鬆編輯您的文件。 建立PDF非常簡單,並且與.NET Framework 4、.NET Core 3.1、.NET 6和5相容。無需使用專有文件格式或不同的API。

本教程提供文件,以逐步引導您使用由開發人員喜愛的IronPDF軟體來完成每個任務。 VB.NET程式碼範例針對您的使用案例設計,讓您能夠輕鬆地在熟悉的環境中查看這些步驟。 這個VB.NET PDF程式庫擁有全面的建立和設置能力,無論是在ASP.NET應用程式、控制台還是桌面中,每個項目都能輕鬆應對。

隨IronPDF一起提供

  • 由我們.NET PDF程式庫開發團隊提供的直接工單支持(真人)
  • 支持使用HTML、ASPX表單、MVC視圖、圖片及您已使用的所有文件格式
  • 使用Microsoft Visual Studio安裝快速部署
  • 免費無限開發,發布許可證$999起售

步驟 1

1. 從IronPDF免費下載VB .NET PDF程式庫

通過NuGet安裝:

在Visual Studio中,右鍵單擊您的項目解決方案管理器,然後選擇"管理NuGet包..."。 從那裡搜尋IronPDF並安裝最新版本。 點擊任意彈出的對話框中的確定。

這適用於任何C# .NET Framework項目(從Framework 4及以上)或.NET Core 2及以上。 它也適用於VB.NET項目。

Install-Package IronPdf

NuGet Package - IronPDF

通過DLL安裝:

或者,下載IronPDF DLL並手動安裝到專案中或從IronPDF下載安裝到GAC。

在任何VB.NET類文件之頂部加上此語句使用IronPDF

Imports IronPdf
Imports IronPdf
VB .NET

如何教程

2. 用VB.NET建立PDF

使用Visual Basic ASP.NET首次建立PDF文件是一件令人驚訝地簡單的事情,特別是相較於使用專有設計API的程式庫如iText

我們可以使用HTML(基於Google Chromium的像素完美渲染引擎)來定義我們的PDF內容並將其簡單地渲染為一個文件。

在VB.NET中建立PDF的最簡單程式碼:

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-1.cs
Module Module1
    Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim document = renderer.RenderHtmlAsPdf("<h1> My First PDF in VB.NET</h1>")
        document.SaveAs("MyFirst.pdf")
    End Sub
End Module
VB .NET

通過使用System.Diagnostics.Process.Start方法,將PDF打開於操作系統的預設PDF查看器中以使專案更具意義。

從URL呈現任何現有的網頁為PDF:

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-3.cs
Imports IronPdf

Module Module1
    Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim document = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/")
        document.SaveAs("UrlToPdf.pdf")
        System.Diagnostics.Process.Start("UrlToPdf.pdf")
    End Sub
End Module
VB .NET

要在PDF/A格式中生成您的PDF,首先在IronPDF中呈現,然後使用Ghostscript轉換為PDF/A。


3. 對VB.NET PDF應用樣式

為了在VB.NET中為PDF內容應用樣式,我們可以充分利用CSS、JavaScript和圖像。 我們可以連結到本地資產或遠端/CDN資產,如Google Fonts。 我們可以使用DataURIs將圖像和資產嵌入為字串到您的HTML中

對於高級設計,我們使用兩階段過程:

  1. 完美編寫和設計HTML,這可能涉及到內部設計人員。
  2. 使用VB.NET和我們的PDF程式庫將該文件渲染為PDF。

將HTML文件渲染為PDF的VB.NET程式碼:

Imports IronPdf

Module Module3
    Sub Main()
        ' Initialize PDF renderer
        Dim Renderer = New HtmlToPdf()

        ' Set rendering options
        Renderer.PrintOptions.CssMediaType = IronPdf.Rendering.PdfPrintOptions.PdfCssMediaType.Print
        Renderer.PrintOptions.EnableHtmlBackgrounds = False
        Renderer.PrintOptions.PaperOrientation = IronPdf.Rendering.PdfPrintOptions.PdfPaperOrientation.Landscape
        Renderer.PrintOptions.RenderDelay = 500 ' milliseconds

        ' Render the HTML file as a PDF
        Dim PDF = Renderer.RenderHtmlFileAsPdf("yourfile.html")

        ' Save PDF file
        PDF.SaveAs("styled_output.pdf")
    End Sub
End Module
Imports IronPdf

Module Module3
    Sub Main()
        ' Initialize PDF renderer
        Dim Renderer = New HtmlToPdf()

        ' Set rendering options
        Renderer.PrintOptions.CssMediaType = IronPdf.Rendering.PdfPrintOptions.PdfCssMediaType.Print
        Renderer.PrintOptions.EnableHtmlBackgrounds = False
        Renderer.PrintOptions.PaperOrientation = IronPdf.Rendering.PdfPrintOptions.PdfPaperOrientation.Landscape
        Renderer.PrintOptions.RenderDelay = 500 ' milliseconds

        ' Render the HTML file as a PDF
        Dim PDF = Renderer.RenderHtmlFileAsPdf("yourfile.html")

        ' Save PDF file
        PDF.SaveAs("styled_output.pdf")
    End Sub
End Module
VB .NET

範例HTML文件

此HTML建立了一個動態、移動的投影片秀,可以在https://github.com/leemark/better-simple-slideshow找到

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-6.cs
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>A simple DIY responsive slideshow made with HTML5, CSS3, and JavaScript</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link href='http://fonts.googleapis.com/css?family=Open+Sans|Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="demo/css/demostyles.css">
        <link rel="stylesheet" href="css/simple-slideshow-styles.css">
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
        <header>
            <h1>A Better Simple Slideshow</h1>
            <p><span class="desc">A simple DIY responsive JavaScript slideshow.</span> [<a href="https://github.com/leemark/better-simple-slideshow">GitHub<span> repo</span></a>]</p>
        </header>
        <div class="bss-slides num1" tabindex="1" autofocus="autofocus">
            <figure>
              <img src="demo/img/medium.jpg" width="100%" /><figcaption>"Medium" by <a href="https://www.flickr.com/photos/thomashawk/14586158819/">Thomas Hawk</a>.</figcaption>
            </figure>
            <figure>
              <img src="demo/img/colorado.jpg" width="100%" /><figcaption>"Colorado" by <a href="https://www.flickr.com/photos/stuckincustoms/88370744">Trey Ratcliff</a>.</figcaption>
            </figure>
            <figure>
              <img src="demo/img/monte-vista.jpg" width="100%" /><figcaption>"Early Morning at the Monte Vista Wildlife Refuge, Colorado" by <a href="https://www.flickr.com/photos/davesoldano/8572429635">Dave Soldano</a>.</figcaption>
            </figure>
            <figure>
              <img src="demo/img/sunrise.jpg" width="100%" /><figcaption>"Sunrise in Eastern Colorado" by <a href="https://www.flickr.com/photos/35528040@N04/6673031153">Pam Morris</a>.</figcaption>
            </figure>
            <figure>
              <img src="demo/img/colorado-colors.jpg" width="100%" /><figcaption>"colorado colors" by <a href="https://www.flickr.com/photos/cptspock/2857543585">Jasen Miller</a>.</figcaption>
            </figure>
        </div> <!-- // bss-slides -->
<div class="content">
<h2>What is it?</h2>
<p>It's a fairly basic slideshow, written in javascript. This is a dual-purpose project, it's meant to be something you can drop right into your page and use if you so choose, but it's also meant as an example/tutorial script showing how to build a simple DIY slideshow from scratch on your own. <a href="http://themarklee.com/2014/10/05/better-simple-slideshow/">Here is a tutorial/walkthrough</a>.</p>
<h2>Features</h2>
<ul>
    <li>fully responsive</li>
    <li>option for auto-advancing slides, or manually advancing by user</li>
    <li>multiple slideshows per-page</li>
    <li>supports arrow-key navigation</li>
    <li>full-screen toggle using HTML5 fullscreen api</li>
    <li>swipe events supported on touch devices (requires <a href="https://github.com/hammerjs/hammer.js">hammer.js</a>)</li>
    <li>written in vanilla JS--this means no jQuery dependency (much &hearts; for <a href="https://github.com/jquery/jquery">jQuery</a> though!)</li>
</ul>
<h2>Getting Started</h2>
<ol>
<li><p>HTML markup for the slideshow should look basically like this, with a container element wrapping the whole thing (doesn't have to be a <span class="code">&lt;div&gt;</span>) and each slide is a <span class="code">&lt;figure&gt;</span>.</p>
<script src="https://gist.github.com/leemark/83571d9f8f0e3ad853a8.js"></script> </li>
<li>Include the script: <span class="code">js/better-simple-slideshow.min.js</span> or <span class="code">js/better-simple-slideshow.js</span></li>
<li>Include the stylesheet <span class="code">css/simple-slideshow-styles.css</span></li>
<li>Initialize the slideshow:
<script src="https://gist.github.com/leemark/479d4ecc4df38fba500c.js"></script>
</li>
</ol>
<h2>Options</h2>
To customize functionality, create an options object, then pass it into <span class="code">makeBSS()</span> as the second argument, as seen below:
<script src="https://gist.github.com/leemark/c6e0f5c47acb7bf9be16.js"></script>
<h2>Demo/Examples</h2>
    <h3>Example #1 (slideshow at top of this page)</h3>
    <p>HTML markup:</p>
    <script src="https://gist.github.com/leemark/19bafdb1abf8f6b4e147.js"></script>
    <p>JavaScript code:</p>
    <script src="https://gist.github.com/leemark/a09d2726b5bfc92ea68c.js"></script>
    <h3>Example #2 (below)</h3>
        <div class="bss-slides num2" tabindex="2">
           <figure>
              <img src="http://themarklee.com/wp-content/uploads/2013/12/snowying.jpg" width="100%" /><figcaption>"Snowying" by <a href="http://www.flickr.com/photos/fiddleoak/8511209344/">fiddleoak</a>.</figcaption>
           </figure>
            <figure>
                <img src="http://themarklee.com/wp-content/uploads/2013/12/starlight.jpg" width="100%" /><figcaption>"Starlight" by <a href="http://www.flickr.com/photos/chaoticmind75/10738494123/in/set-72157626146319517">ChaoticMind75</a>.</figcaption>
           </figure>
           <figure>
              <img src="http://themarklee.com/wp-content/uploads/2013/12/snowstorm.jpg" width="100%" /><figcaption>"Snowstorm" by <a href="http://www.flickr.com/photos/tylerbeaulawrence/8539457508/">Beaulawrence</a>.</figcaption>
           </figure>
            <figure>
              <img src="http://themarklee.com/wp-content/uploads/2013/12/misty-winter-afternoon.jpg" width="100%" /><figcaption>"Misty winter afternoon" by <a href="http://www.flickr.com/photos/22746515@N02/5277611659/">Bert Kaufmann</a>.</figcaption>
           </figure>
            <figure>
              <img src="http://themarklee.com/wp-content/uploads/2013/12/good-morning.jpg" width="100%" /><figcaption>"Good Morning!" by <a href="http://www.flickr.com/photos/frank_wuestefeld/4306107546/">Frank Wuestefeld</a>.</figcaption>
           </figure>
        </div> <!-- // bss-slides -->
<p>HTML markup:</p>
<script src="https://gist.github.com/leemark/de90c78cb73673650a5a.js"></script>
<p>JavaScript code:</p>
<script src="https://gist.github.com/leemark/046103061c89cdf07e4a.js"></script>
</div> <!-- // content -->
<footer>Example photos are property of their respective owners, all code is <a href="https://github.com/leemark/better-simple-slideshow/blob/gh-pages/LICENSE">freely licensed for your use</a>. <br>Made especially for you by <a href="http://themarklee.com">Mark Lee</a> aka <a href="http://twitter.com/@therealmarklee">@therealmarklee</a> <br><span>&#9774; + &hearts;</span></footer>
<script src="demo/js/hammer.min.js"></script><!-- for swipe support on touch interfaces -->
<script src="js/better-simple-slideshow.min.js"></script>
<script>
var opts = {
    auto : {
        speed : 3500,
        pauseOnHover : true
    },
    fullScreen : false,
    swipe : true
};
makeBSS('.num1', opts);
var opts2 = {
    auto : false,
    fullScreen : true,
    swipe : true
};
makeBSS('.num2', opts2);
</script>
</body>
</html>
HTML

如您所見,此範例中使用了完整的HTML網頁功能"萬能搭配"。 渲染是由IronPDF使用來自Google的Chromium HTML引擎和v8 JavaScript引擎在內部執行的。 它們不需要安裝在您的系統上,整個包會在您使用IronPDF時自動新增到您的專案中。

3.1. 新增頁眉和頁腳

一旦您有了漂亮的PDF渲染,您可能想要新增吸引人的頁眉和頁腳。

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-7.cs
Imports IronPdf
Imports IronSoftware.Drawing

Module Module1
    Sub Main()
        Dim renderer = New ChromePdfRenderer()
        renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Print
        renderer.RenderingOptions.PrintHtmlBackgrounds = False
        renderer.RenderingOptions.PaperOrientation = Rendering.PdfPaperOrientation.Landscape
        renderer.RenderingOptions.WaitFor.RenderDelay(150)
        renderer.RenderingOptions.TextHeader.CenterText = "VB.NET PDF Slideshow"
        renderer.RenderingOptions.TextHeader.DrawDividerLine = True
        renderer.RenderingOptions.TextHeader.FontSize = "13"
        renderer.RenderingOptions.TextFooter.RightText = "page {page} of {total-pages}"
        renderer.RenderingOptions.TextFooter.Font = FontTypes.Arial
        renderer.RenderingOptions.TextFooter.FontSize = "9"
        Dim document = renderer.RenderHtmlFileAsPdf("..\..\slideshow\index.html")
        document.SaveAs("Html5WithHeader.pdf")
        System.Diagnostics.Process.Start("Html5WithHeader.pdf")
    End Sub
End Module
VB .NET

您可以按照VB.NET PDF開發者API線上參考指南所述來新增基於HTML的頁眉和頁腳。

您可以下載和探索這個"VB.NET HTML到PDF"項目的源程式碼作為VB.NET Visual Studio專案


4. 建立具有動態內容的PDF:2種方法

從歷史上看,PDF '模板化'對於軟體工程師來說是一項艱巨的任務。 由於報告中的內容型別和長度變化不定,將內容蓋印到PDF模板上很少奏效。 幸好,HTML在處理動態資料方面非常優秀。

針對這一點,我們有兩種方法可以前進:

  1. HTML的字串模板然後使用.NET轉換為PDF
  2. 將內容呈現在ASP.NET網頁並將頁面渲染為PDF

4.1. 方法 1 - ASP.NET - 使用VB.NET Web Forms將ASPX轉換為PDF

幸運的是,這個解決方案出人意料地簡單。 任何.NET Web Form(包括Razor)的變體都可以通過VB.NET程式碼在VB.NET程式碼後面中的Page_Load子程式中渲染為PDF文件。

PDF文件可以設置為內容處置中的以在瀏覽器中顯示或作為文件下載。

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-8.cs
Imports IronPdf

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim PdfOptions = New IronPdf.ChromePdfRenderOptions()
    IronPdf.AspxToPdf.RenderThisPageAsPDF(AspxToPdf.FileBehavior.Attachment, "MyPdf.pdf", PdfOptions)
End Sub
VB .NET

4.2. 方法 2 - HTML使用字串模板轉換為PDF

為了建立包含特定實例資料的動態PDF文件,請建立一個HTML字串以匹配您希望渲染為PDF的資料。

這可能是VB.NET中HTML到PDF解決方案的最大優勢 - 能夠輕鬆和直觀地建立動態PDF文件和報告,通過即時建立HTML。

使用VB.NET中的String.Format方法的最簡單版本:

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-9.cs
Imports IronPdf

Module Module1
    Sub Main()
        Dim renderer = New ChromePdfRenderer()
        Dim Html = "Hello {0}"
        String.Format(Html, "World")
        Dim document = renderer.RenderHtmlAsPdf(Html)
        document.SaveAs("HtmlTemplate.pdf")
        System.Diagnostics.Process.Start("HtmlTemplate.pdf")
    End Sub
End Module
VB .NET

隨著PDF的複雜性增加,字串也會變得更加複雜。 考慮使用Razor這樣的模板框架:https://github.com/rexm/Handlebars.Net


Icon Quote related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

我最喜歡的程式庫是IronPDF。它允許快速高效地操作PDF文件。它還有許多有價值的功能,例如導出到PDF/A格式和數位簽署PDF文件。

Milan Jovanovic related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

Milan Jovanovic

Microsoft MVP

查看案例研究
Icon Quote related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

IronOCR意味著我們每年可以從手動處理中節省$40,000,同時提高生產力,釋放資源以進行高影響的任務。我會強烈推薦它。

Brent Matzelle related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

Brent Matzelle

首席技術官,OPYN

查看案例研究
Icon Quote related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

IronSuite在我們的運營中扮演著至關重要的角色。這些工具增加了包括建立平面圖和改善庫存管理在內的業務效率。

David Jones related to 4.2. 方法 2 - HTML使用字串模板轉換為PDF

David Jones

首席軟體工程師,Agorus Build

查看案例研究

5. 使用VB.NET編輯PDF文件

VB.NET的IronPDF允許編輯、加密、加水印,甚至將PDF文件轉換為純文字:

5.1. 在VB中將多個PDF文件合併為一個文件

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-10.cs
Dim pdfs = New List(Of PdfDocument)
pdfs.Add(PdfDocument.FromFile("A.pdf"))
pdfs.Add(PdfDocument.FromFile("B.pdf"))
pdfs.Add(PdfDocument.FromFile("C.pdf"))
Dim mergedPdf As PdfDocument = PdfDocument.Merge(pdfs)
mergedPdf.SaveAs("merged.pdf")
mergedPdf.Dispose()
For Each pdf As PdfDocument In pdfs
    pdf.Dispose()
Next
VB .NET

5.2. 為PDF新增封面頁

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-11.cs
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))
VB .NET

5.3. 從PDF中移除最後一頁

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-12.cs
pdf.RemovePage((pdf.PageCount - 1))
VB .NET

5.4. 使用128位加密加密PDF

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-13.cs
// Save with a strong encryption password.
pdf.Password = "my.secure.password";
pdf.SaveAs("secured.pdf")
VB .NET

5.5. 在頁面上蓋上額外的HTML內容

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-14.cs
Imports IronPdf
Imports IronPdf.Editing

Module Module1
    Sub Main()
        Dim renderer = New ChromePdfRenderer
        Dim pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
        Dim stamp = New HtmlStamper()
        stamp.Html = "<h2>Completed</h2>"
        stamp.Opacity = 50
        stamp.Rotation = -45
        stamp.VerticalAlignment = VerticalAlignment.Top
        stamp.VerticalOffset = New Length(10)
        pdf.ApplyStamp(stamp)
        pdf.SaveAs("C:\Path\To\Stamped.pdf")
    End Sub
End Module
VB .NET

5.6. 使用HTML向PDF新增分頁

最簡單的方法是使用HTML和CSS

:path=/static-assets/pdf/content-code-examples/tutorials/vb-net-pdf-15.cs
<div style='page-break-after: always;'>&nbsp;</div>
HTML

更多.NET PDF教程

您可能還對以下內容感興趣:


結論

在本教程中,我們發現了使用VB.NET作為我們的編程語言來獲得VB.NET到PDF結果的6種方法。

  • HTML字串到PDF
  • 在VB.NET中使用HTML字串建立PDF來定義其內容
  • 將現有URL渲染為PDF文件
  • 從HTML文件生成PDF
  • VB.NET中的HTML模板以及轉換為動態PDF
  • 使用實時資料轉換ASP.NET頁面,例如ASPX為PDF文件

對於每個,我們使用流行的IronPDF VB.NET程式庫在.NET項目中直接將HTML轉換為PDF文件。


教程快速存取

Brand Visual Studio related to 教程快速存取

下載此教程作為源程式碼

此教程的免費VB.NET HTML到PDF源程式碼可作為壓縮的Visual Studio專案文件下載。

下載

在GitHub上探索本教程

您也可能對我們在GitHub上的廣泛VB.NET PDF生成和操作範例感興趣。探索源程式碼是學習的最快方式,而GitHub是線上進行探索的最佳途徑。希望這些範例能幫助您掌握VB專案中的PDF相關功能。

在VB.NET和C#源碼的ASP.NET中建立PDF 使用IronPDF在VB.NET中渲染HTML為PDF的簡單Hello World專案 深入探索HTML到PDF使用VB.NET
Github Icon related to 教程快速存取
Html To Pdf Icon related to 教程快速存取

下載C# PDF快速入門指南

為了使您的.NET應用程式中PDF的開發更加輕鬆,我們整理了一份作為PDF文件的快速入門指南。此"快速查閱表"提供生成和編輯PDF於C#和VB.NET中的常用功能和範例的快速存取,並將節省使用IronPDF於您的.NET項目中的啟動時間。

下載

查看API參考

探索IronPDF的API參考,概述IronPDF的所有功能、命名空間、類別、方法、字段和枚舉的詳細資訊。

查看API參考
Documentation related to 教程快速存取

常見問題

如何在VB.NET中將HTML轉換為PDF?

您可以使用IronPDF中的HtmlToPdf類的RenderHtmlAsPdf方法將HTML字串轉換為PDF。此方法允許您包含CSS和JavaScript以進行樣式和動態內容。

設置VB.NET PDF程式庫涉及哪些步驟?

要設置VB.NET PDF程式庫,您需要在Visual Studio中透過NuGet安裝IronPDF,搜尋“IronPDF”並將其新增到您的專案中。或者,您可以從IronPDF網站下載DLL並手動在您的專案中引用它。

我可以使用該程式庫從ASP.NET頁面建立PDF嗎?

是的,IronPDF可以直接將ASP.NET網頁渲染為PDF文件。這是透過渲染頁面URL並將其轉換為PDF實現的,使用RenderUrlAsPdf方法。

如何在從HTML建立PDF時應用CSS樣式?

IronPDF支持在渲染HTML為PDF時應用CSS樣式。您可以直接在您的HTML字串中包含CSS或引用外部樣式表,以確保您的PDF保持所需的樣式。

是否可以為PDF文件新增水印?

是的,您可以使用IronPDF為PDF文件新增水印。您可以在PDF的每一頁上覆蓋文字或圖像,以在文件建立過程中充當水印。

如何將多個PDF合併為單個文件?

使用IronPDF中的PdfDocument.Merge方法將多個PDF文件合併為一個統一的文件。這對於合併各種報告或文件非常有用。

加密PDF文件有哪些選項可用?

IronPDF提供PdfSecurity類來啟用PDF文件的加密。您可以設置密碼和加密選項來在保存您的PDF之前保護它們。

我可以在從HTML建立的PDF中包含JavaScript嗎?

是的,IronPDF允許您在將HTML轉換為PDF時包含JavaScript內容。這對於向PDF新增互動元素或動態內容非常有用。

我可以在哪裡找到更多使用VB.NET PDF程式庫的資源或範例?

您可以在IronPDF文件、GitHub程式碼庫和可下載的Visual Studio專案中找到更多資源和範例。這些資源提供了VB.NET中的各種使用案例的全面指導。

如何在PDF文件中新增頁眉和頁尾?

在IronPDF中,您可以透過設置PrintOptions.HeaderPrintOptions.Footer屬性與HTML內容,為您的PDF新增頁眉和頁尾,允許使用動態和樣式化的頁眉和頁尾。

IronPDF是否完全相容VB.NET專案中的.NET 10?

是的,IronPDF完全相容.NET 10並在VB.NET專案中無縫運行。它支持所有現代.NET版本,包括桌面、網頁、控制台和雲端應用中的.NET 10,允許您使用最新的運行時、語言改進和性能增強,而不需特殊的迴避。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備開始了嗎?
Nuget 下載 20,296,129 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

還在捲動嗎?

想快速獲得證明嗎? PM > Install-Package IronPdf
執行範例 看您的HTML變成PDF。