Tài liệu .NET có thể giúp ứng dụng của bạn chuyển đổi tài liệu từ định dạng này sang định dạng khác.Bạn sẽ chỉ cần tải [] một tài liệu và lưu [] vào một định dạng mong muốn.
You'll need only to Load[] a document and
Save[] to a desired format.
using System.IO;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main[string[] args]
{
ConvertFromFile[];
ConvertFromStream[];
}
///
/// Convert HTML to Text [file to file].
///
///
/// Details: //sautinsoft.com/products/document/help/net/developer-guide/convert-html-to-text-in-csharp-vb.php
///
static void ConvertFromFile[]
{
string inpFile = @"..\..\example.html";
string outFile = @"Result.txt";
DocumentCore dc = DocumentCore.Load[inpFile];
dc.Save[outFile];
// Open the result for demonstration purposes.
System.Diagnostics.Process.Start[new System.Diagnostics.ProcessStartInfo[outFile] { UseShellExecute = true }];
}
///
/// Convert HTML to Text [using Stream].
///
///
/// Details: //sautinsoft.com/products/document/help/net/developer-guide/convert-html-to-text-in-csharp-vb.php
///
static void ConvertFromStream[]
{
// We need files only for demonstration purposes.
// The conversion process will be done completely in memory.
string inpFile = @"..\..\example.html";
string outFile = @"ResultStream.txt";
byte[] inpData = File.ReadAllBytes[inpFile];
byte[] outData = null;
using [MemoryStream msInp = new MemoryStream[inpData]]
{
// Load a document.
DocumentCore dc = DocumentCore.Load[msInp, new HtmlLoadOptions[]];
// Save the document to Text format.
using [MemoryStream outMs = new MemoryStream[]]
{
dc.Save[outMs, new TxtSaveOptions[] ];
outData = outMs.ToArray[];
}
// Show the result for demonstration purposes.
if [outData != null]
{
File.WriteAllBytes[outFile, outData];
System.Diagnostics.Process.Start[new System.Diagnostics.ProcessStartInfo[outFile] { UseShellExecute = true }];
}
}
}
}
}
Tải xuống.
Imports System.IO
Imports SautinSoft.Document
Namespace Example
Friend Class Program
Shared Sub Main[ByVal args[] As String]
ConvertFromFile[]
ConvertFromStream[]
End Sub
'''
''' Convert HTML to Text [file to file].
'''
'''
''' Details: //sautinsoft.com/products/document/help/net/developer-guide/convert-html-to-text-in-csharp-vb.php
'''
Private Shared Sub ConvertFromFile[]
Dim inpFile As String = "..\example.html"
Dim outFile As String = "Result.txt"
Dim dc As DocumentCore = DocumentCore.Load[inpFile]
dc.Save[outFile]
' Open the result for demonstration purposes.
System.Diagnostics.Process.Start[New System.Diagnostics.ProcessStartInfo[outFile] With {.UseShellExecute = True}]
End Sub
'''
''' Convert HTML to Text [using Stream].
'''
'''
''' Details: //sautinsoft.com/products/document/help/net/developer-guide/convert-html-to-text-in-csharp-vb.php
'''
Private Shared Sub ConvertFromStream[]
' We need files only for demonstration purposes.
' The conversion process will be done completely in memory.
Dim inpFile As String = "..\example.html"
Dim outFile As String = "ResultStream.txt"
Dim inpData[] As Byte = File.ReadAllBytes[inpFile]
Dim outData[] As Byte = Nothing
Using msInp As New MemoryStream[inpData]
' Load a document.
Dim dc As DocumentCore = DocumentCore.Load[msInp, New HtmlLoadOptions[]]
' Save the document to Text format.
Using outMs As New MemoryStream[]
dc.Save[outMs, New TxtSaveOptions[]]
outData = outMs.ToArray[]
End Using
' Show the result for demonstration purposes.
If outData IsNot Nothing Then
File.WriteAllBytes[outFile, outData]
System.Diagnostics.Process.Start[New System.Diagnostics.ProcessStartInfo[outFile] With {.UseShellExecute = True}]
End If
End Using
End Sub
End Class
End Namespace
Tải xuống.
Nếu bạn cần một ví dụ về mã mới hoặc có một câu hỏi: Gửi email cho chúng tôi tại hoặc hỏi tại Trò chuyện trực tuyến [góc đáy bên phải của trang này] hoặc sử dụng biểu mẫu bên dưới:Online Chat [right-bottom corner of this page] or use the Form below:
Mẫu này cho thấy cách sử dụng SELECTPDF HTML sang Trình chuyển đổi hình ảnh để chuyển đổi mã HTML thô thành PNG, JPEG hoặc BMP, cũng đặt một vài thuộc tính. Web Width: PX
px
Trang web Chiều cao: PX [để trống để phát hiện tự động]
px
[leave empty to auto detect]
Mã mẫu vb.net
Imports System.Drawing.Imaging Public Class convert_html_code_to_image Inherits System.Web.UI.Page Protected Sub Page_Load[ByVal sender As Object, ByVal e As System.EventArgs] _ Handles Me.Load If Not IsPostBack Then TxtHtmlCode.Text = "" & vbCr & vbLf & " " & vbCr & vbLf & _ "
" & vbCr & vbLf & " Hello World from selectpdf.com." _ & vbCr & vbLf & "
" & vbCr & vbLf & "
" & vbCr & vbLf _ & "
" & vbCr & vbLf & "
" & vbCr & vbLf & _ " Hello World from selectpdf.com." & vbCr & vbLf & "
" _ & vbCr & vbLf & "
" & vbCr & vbLf & " " _ & vbCr & vbLf & "" & vbCr & vbLf End If End Sub Protected Sub BtnSubmit_Click[sender As Object, e As EventArgs] ' read parameters from the webpage Dim htmlString As String = TxtHtmlCode.Text Dim baseUrl As String = TxtBaseUrl.Text Dim image_format As String = DdlImageFormat.SelectedValue Dim imgFormat As ImageFormat = ImageFormat.Png If image_format = "jpg" Then imgFormat = ImageFormat.Jpeg ElseIf image_format = "bmp" Then imgFormat = ImageFormat.Bmp End If Dim webPageWidth As Integer = 1024 Try webPageWidth = Convert.ToInt32[TxtWidth.Text] Catch End Try Dim webPageHeight As Integer = 0 Try webPageHeight = Convert.ToInt32[TxtHeight.Text] Catch End Try ' instantiate a html to image converter object Dim imgConverter As New HtmlToImage[] ' set converter options imgConverter.WebPageWidth = webPageWidth imgConverter.WebPageHeight = webPageHeight ' create a new image converting an url Dim image As System.Drawing.Image = _ imgConverter.ConvertHtmlString[htmlString, baseUrl] ' send image to browser Response.Clear[] Response.ClearHeaders[] Response.AddHeader["Content-Type", "image/" + imgFormat.ToString[].ToLower[]] Response.AppendHeader["content-disposition", _ "attachment;filename=""image." + image_format + """"] image.Save[Response.OutputStream, imgFormat] Response.[End][] End Sub End Class