Last active
August 3, 2021 07:22
-
-
Save aspose-com-gists/f3606888162b6b9cad4e80c485ee4ec3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains examples for Aspose.HTML for .NET in C# language. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Initialize configuration object and set up the page-margins for the document | |
using (Configuration configuration = new Configuration()) | |
{ | |
// Get the User Agent service | |
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>(); | |
// Set the style of custom margins and create marks on it | |
userAgent.UserStyleSheet = @"@page | |
{ | |
/* Page margins should be not empty in order to write content inside the margin-boxes */ | |
margin-top: 1cm; | |
margin-left: 2cm; | |
margin-right: 2cm; | |
margin-bottom: 2cm; | |
/* Page counter located at the bottom of the page */ | |
@bottom-right | |
{ | |
-aspose-content: ""Page "" currentPageNumber() "" of "" totalPagesNumber(); | |
color: green; | |
} | |
/* Page title located at the top-center box */ | |
@top-center | |
{ | |
-aspose-content: ""Hello World Document Title!!!""; | |
vertical-align: bottom; | |
color: blue; | |
} | |
}"; | |
// Initialize an HTML document | |
using (HTMLDocument document = new HTMLDocument("<div>Hello World!!!</div>", ".", configuration)) | |
{ | |
// Initialize an output device | |
using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice("output.xps")) | |
{ | |
// Send the document to the output device | |
document.RenderTo(device); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an empty HTML document | |
using (var document = new HTMLDocument()) | |
{ | |
// Create a mutation observer instance | |
var observer = new Aspose.Html.Dom.Mutations.MutationObserver((mutations, mutationObserver) => | |
{ | |
foreach (var record in mutations) | |
{ | |
foreach (var node in record.AddedNodes) | |
{ | |
Console.WriteLine("The '" + node + "' node was added to the document."); | |
} | |
} | |
}); | |
// configuration of the observer | |
var config = new Aspose.Html.Dom.Mutations.MutationObserverInit | |
{ | |
ChildList = true, | |
Subtree = true, | |
CharacterData = true | |
}; | |
// pass in the target node to observe with the specified configuration | |
observer.Observe(document.Body, config); | |
// Now, we are going to modify DOM tree to check | |
// Create an paragraph element and append it to the document body | |
var p = document.CreateElement("p"); | |
document.Body.AppendChild(p); | |
// Create a text and append it to the paragraph | |
var text = document.CreateTextNode("Hello World"); | |
p.AppendChild(text); | |
Console.WriteLine("Waiting for mutation. Press any key to continue..."); | |
Console.ReadLine(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an empty HTML document | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Create the Canvas element | |
var canvas = (Aspose.Html.HTMLCanvasElement)document.CreateElement("canvas"); | |
// with a specified size | |
canvas.Width = 300; | |
canvas.Height = 150; | |
// and append it to the document body | |
document.Body.AppendChild(canvas); | |
// Get the canvas rendering context to draw | |
var context = (Aspose.Html.Dom.Canvas.ICanvasRenderingContext2D)canvas.GetContext("2d"); | |
// Prepare the gradient brush | |
var gradient = context.CreateLinearGradient(0, 0, canvas.Width, 0); | |
gradient.AddColorStop(0, "magenta"); | |
gradient.AddColorStop(0.5, "blue"); | |
gradient.AddColorStop(1.0, "red"); | |
// Assign brush to the content | |
context.FillStyle = gradient; | |
context.StrokeStyle = gradient; | |
// Write the Text | |
context.FillText("Hello World!", 10, 90, 500); | |
// Fill the Rectangle | |
context.FillRect(0, 95, 300, 20); | |
// Create the PDF output device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("canvas.pdf")) | |
{ | |
// Render HTML5 Canvas to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a document with HTML5 Canvas inside and save it to the file 'document.html' | |
var code = @" | |
<canvas id=myCanvas width='200' height='100' style='border:1px solid #d3d3d3;'></canvas> | |
<script> | |
var c = document.getElementById('myCanvas'); | |
var context = c.getContext('2d'); | |
context.font = '20px Arial'; | |
context.fillStyle = 'red'; | |
context.fillText('Hello World', 40, 50); | |
</script>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new HTMLDocument("document.html")) | |
{ | |
// Convert HTML to PDF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Initialize an instance of HTML document from 'https://httpbin.org/forms/post' url | |
using (var document = new Aspose.Html.HTMLDocument(@"https://httpbin.org/forms/post")) | |
{ | |
// Create an instance of Form Editor | |
using (var editor = Aspose.Html.Forms.FormEditor.Create(document, 0)) | |
{ | |
// You can fill the data up using direct access to the input elements, like this: | |
editor["custname"].Value = "John Doe"; | |
document.Save("out.html"); | |
// or this: | |
var comments = editor.GetElement<Aspose.Html.Forms.TextAreaElement>("comments"); | |
comments.Value = "MORE CHEESE PLEASE!"; | |
// or even by performing a bulk operation, like this one: | |
editor.Fill(new Dictionary<string, string>() | |
{ | |
{"custemail", "john.doe@gmail.com"}, | |
{"custtel", "+1202-555-0290"} | |
}); | |
// Create an instance of form submitter | |
using (var submitter = new Aspose.Html.Forms.FormSubmitter(editor)) | |
{ | |
// Submit the form data to the remote server. | |
// If you need you can specify user-credentials and timeout for the request, etc. | |
var result = submitter.Submit(); | |
// Check the status of the result object | |
if (result.IsSuccess) | |
{ | |
// Check whether the result is in json format | |
if (result.ResponseMessage.Headers.ContentType.MediaType == "application/json") | |
{ | |
// Dump result data to the console | |
Console.WriteLine(result.Content.ReadAsString()); | |
} | |
else | |
{ | |
// Load the result data as an HTML document | |
using (var resultDocument = result.LoadDocument()) | |
{ | |
// Inspect HTML document here. | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize an HTML document | |
using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello World!!</span>", ".")) | |
{ | |
// Convert HTML to Image by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.jpg")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
String SimpleStyledFilePath = dataDir + "FirstFile.html"; | |
using (FileStream fs = File.Create(SimpleStyledFilePath)) | |
using (StreamWriter sw = new StreamWriter(fs)) | |
{ | |
sw.Write( | |
@"<style> | |
.st | |
{ | |
color: green; | |
} | |
</style> | |
<div id=id1>Aspose.Html rendering Text in Black Color</div> | |
<div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div> | |
<div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div> | |
<div id=id3 class=''st'' style='color: red;'><font face='Arial'>Aspose.Html rendering Text in Red Color</font></div> | |
"); | |
} | |
string pdf_output; | |
// Create HtmlRenderer object | |
using (Aspose.Html.Rendering.HtmlRenderer pdf_renderer = new Aspose.Html.Rendering.HtmlRenderer()) | |
// Create HtmlDocument instnace while passing path of already created HTML file | |
using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(SimpleStyledFilePath)) | |
{ | |
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px | |
Aspose.Html.Rendering.Pdf.PdfRenderingOptions pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)), | |
AdjustToWidestPage = false | |
}, | |
}; | |
pdf_output = dataDir + "not-adjusted-to-widest-page_out.pdf"; | |
using (Aspose.Html.Rendering.Pdf.PdfDevice device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, pdf_output)) | |
{ | |
// Render the output | |
pdf_renderer.Render(device, html_document); | |
} | |
// Set the page size less than document min-width and enable AdjustToWidestPage option. The page size of the resulting file will be changed according to content width | |
pdf_options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)), | |
AdjustToWidestPage = true | |
}, | |
}; | |
pdf_output = dataDir + "adjusted-to-widest-page_out.pdf"; | |
using (Aspose.Html.Rendering.Pdf.PdfDevice device = new Aspose.Html.Rendering.Pdf.PdfDevice(pdf_options, pdf_output)) | |
{ | |
// Render the output | |
pdf_renderer.Render(device, html_document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Set input file name. | |
String SimpleStyledFilePath = dataDir + "FirstFile.html"; | |
using (FileStream fs = File.Create(SimpleStyledFilePath)) | |
using (StreamWriter sw = new StreamWriter(fs)) | |
{ | |
sw.Write( | |
@"<style> | |
.st | |
{ | |
color: green; | |
} | |
</style> | |
<div id=id1>Aspose.Html rendering Text in Black Color</div> | |
<div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div> | |
<div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div> | |
<div id=id3 class=''st'' style='color: red;'>Aspose.Html rendering Text in Red Color</div> | |
"); | |
} | |
// Create HtmlRenderer object | |
using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer()) | |
// Create HtmlDocument instnace while passing path of already created HTML file | |
using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(SimpleStyledFilePath)) | |
{ | |
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px | |
Aspose.Html.Rendering.Xps.XpsRenderingOptions xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)), | |
AdjustToWidestPage = false | |
}, | |
}; | |
string output = dataDir + "not-adjusted-to-widest-page_out.xps"; | |
using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(xps_options, output)) | |
{ | |
// Render the output | |
renderer.Render(device, html_document); | |
} | |
// Set the page size less than document min-width and enable AdjustToWidestPage option | |
// The page size of the resulting file will be changed according to content width | |
xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)), | |
AdjustToWidestPage = true | |
}, | |
}; | |
output = dataDir + "adjusted-to-widest-page_out.xps"; | |
using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(xps_options, output)) | |
{ | |
// render the output | |
renderer.Render(device, html_document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new HTMLDocument(dataDir + "canvas.html")) | |
{ | |
// Create an instance of HTML renderer and XPS output device | |
using (var renderer = new Rendering.HtmlRenderer()) | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(dataDir + "canvas.pdf")) | |
{ | |
// Render the document to the specified device | |
renderer.Render(device, document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source EPUB document | |
FileStream epubDocumentStream = File.OpenRead(dataDir + "input.epub"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Output file path | |
string outputFile = dataDir + "EPUBtoImageOutput.jpeg"; | |
// Convert SVG to Image | |
Converter.ConvertEPUB(epubDocumentStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source EPUB document | |
FileStream fileStream = File.OpenRead(dataDir + "input.epub"); | |
// Initialize pdfSaveOptions | |
PdfSaveOptions options = new PdfSaveOptions() | |
{ | |
JpegQuality = 100 | |
}; | |
// Output file path | |
string outputFile = dataDir + "EPUBtoPDF_Output.pdf"; | |
// Convert EPUB to PDF | |
Converter.ConvertEPUB(fileStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source EPUB document | |
FileStream epubDocumentStream = File.OpenRead(dataDir + "input.epub"); | |
// Initialize XpsSaveOptions | |
XpsSaveOptions options = new XpsSaveOptions() | |
{ | |
BackgroundColor = System.Drawing.Color.Cyan | |
}; | |
// Output file path | |
string outputFile = dataDir + "EPUBtoXPS_Output.xps"; | |
// Convert EPUB to XPS | |
Converter.ConvertEPUB(epubDocumentStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Bmp); | |
// Output file path | |
string outputFile = dataDir + "HTMLtoBMP_Output.bmp"; | |
// Convert HTML to BMP | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
DocSaveOptions options = new DocSaveOptions(); | |
options.DocumentFormat = Rendering.Doc.DocumentFormat.DOCX; | |
Converter.ConvertHTML(htmlDocument, options, dataDir + "HTMLtoDOCX_out.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif); | |
// Output file path | |
string outputFile = dataDir + "HTMLtoGIF_Output.gif"; | |
// Convert HTML to GIF | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Output file path | |
string outputFile = dataDir + "HTMLtoJPEG_Output.jpeg"; | |
// Convert HTML to JPEG | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", dataDir)) | |
{ | |
// Create MarkdownSaveOptions object | |
var options = new Aspose.Html.Saving.MarkdownSaveOptions(); | |
// Set the rules: only <a>, <img> and <p> elements will be converted to markdown. | |
options.Features = MarkdownFeatures.Link | MarkdownFeatures.Image | MarkdownFeatures.AutomaticParagraph; | |
document.Save(dataDir + "Markdown.md", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>" + | |
"<p>my second paragraph</p>", dataDir)) | |
{ | |
document.Save(dataDir + "Markdown.md", Saving.HTMLSaveFormat.Markdown); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", dataDir)) | |
{ | |
// Save to markdown by using default for the GIT formatting model | |
document.Save(dataDir + "Markdown.md", Saving.MarkdownSaveOptions.Git); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML Document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize MHTMLSaveOptions | |
MHTMLSaveOptions options = new MHTMLSaveOptions(); | |
// Set the resource handling rules | |
options.ResourceHandlingOptions.MaxHandlingDepth = 1; | |
// Output file path | |
string outputPDF = dataDir + "HTMLtoMHTML_Output.mht"; | |
// Convert HTML to MHTML | |
Converter.ConvertHTML(htmlDocument, options, outputPDF); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize PdfSaveOptions | |
PdfSaveOptions options = new PdfSaveOptions | |
{ | |
JpegQuality = 100 | |
}; | |
// Output file path | |
string outputPDF = dataDir + "HTMLtoPDF_Output.pdf"; | |
// Convert HTML to PDF | |
Converter.ConvertHTML(htmlDocument, options, outputPDF); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Png); | |
// Output file path | |
string outputFile = dataDir + "HTMLtoPNG_Output.png"; | |
// Convert HTML to PNG | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Tiff); | |
// Output file path | |
string outputFile = dataDir + "HTMLtoPNG_Output.tif"; | |
// Convert HTML to TIFF | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source HTML document | |
HTMLDocument htmlDocument = new HTMLDocument(dataDir + "input.html"); | |
// Initialize XpsSaveOptions | |
XpsSaveOptions options = new XpsSaveOptions | |
{ | |
BackgroundColor = System.Drawing.Color.Cyan | |
}; | |
// Output file path | |
string outputFile = dataDir + "input.xps"; | |
// Convert HTML to XPS | |
Converter.ConvertHTML(htmlDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Convert markdown to HTML | |
Converter.ConvertMarkdown(dataDir + "Markdown.md", dataDir + "MarkdownToHTML.html"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source MHTML document | |
FileStream fileStream = File.OpenRead(dataDir + "sample.mht"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Output file path | |
string outputFile = dataDir + "MHTMLtoImage.jpeg"; | |
// Convert SVG to Image | |
Converter.ConvertMHTML(fileStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source MHTML document | |
FileStream fileStream = File.OpenRead(dataDir + "sample.mht"); | |
// Initialize pdfSaveOptions | |
PdfSaveOptions options = new PdfSaveOptions() | |
{ | |
JpegQuality = 100 | |
}; | |
// Output file path | |
string outputFile = dataDir + "MHTMLtoPDF_Output.pdf"; | |
// Convert MHTML to PDF | |
Converter.ConvertMHTML(fileStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source EPUUB document | |
FileStream fileStream = File.OpenRead(dataDir + "sample.mht"); | |
// Initialize XpsSaveOptions | |
XpsSaveOptions options = new XpsSaveOptions() | |
{ | |
BackgroundColor = System.Drawing.Color.Cyan | |
}; | |
// Output file path | |
string outputFile = dataDir + "MHTMLtoXPS_Output.xps"; | |
// Convert MHTML to XPS | |
Converter.ConvertMHTML(fileStream, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source SVG document | |
SVGDocument svgDocument = new SVGDocument(dataDir + "input.svg"); | |
// Initialize ImageSaveOptions | |
ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Jpeg); | |
// Output file path | |
string outputFile = dataDir + "SVGtoImage_Output.jpeg"; | |
// Convert SVG to Image | |
Converter.ConvertSVG(svgDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source SVG document | |
SVGDocument svgDocument = new SVGDocument(dataDir + "input.svg"); | |
// Initialize pdfSaveOptions | |
PdfSaveOptions options = new PdfSaveOptions() | |
{ | |
JpegQuality = 100 | |
}; | |
// Output file path | |
string outputFile = dataDir + "SVGtoPDF_Output.pdf"; | |
// Convert SVG to PDF | |
Converter.ConvertSVG(svgDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Source SVG document | |
SVGDocument svgDocument = new SVGDocument(dataDir + "input.svg"); | |
// Initialize XpsSaveOptions | |
XpsSaveOptions options = new XpsSaveOptions() | |
{ | |
BackgroundColor = System.Drawing.Color.Cyan | |
}; | |
// Output file path | |
string outputFile = dataDir + "SVGtoXPS_Output.xps"; | |
// Convert SVG to XPS | |
Converter.ConvertSVG(svgDocument, options, outputFile); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp); | |
// Call the ConvertEPUB method to convert the EPUB file to BMP. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.bmp"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Gif); | |
// Call the ConvertEPUB method to convert the EPUB file to GIF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.gif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg); | |
// Call the ConvertEPUB method to convert the EPUB file to JPG. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Opens an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png); | |
// Call the ConvertEPUB method to convert the EPUB file to PNG. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Tiff); | |
// Call the ConvertEPUB method to convert the EPUB file to TIFF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.tiff"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert EPUB to Image by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), | |
streamProvider); | |
// Get access to the memory streams that contain the resulted data | |
for (int i = 0; i < streamProvider.Streams.Count; i++) | |
{ | |
var memory = streamProvider.Streams[i]; | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the page to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create($"page_{i + 1}.jpg")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Initailize the ImageSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg) | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertEPUB method to convert the EPUB file to JPG. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Call the ConvertEPUB method to convert the EPUB file to image. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of PdfSaveOptions. | |
var options = new Aspose.Html.Saving.PdfSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert EPUB to PDF by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the resulted data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.pdf")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of the PdfSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.PdfSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of XpsSaveOptions. | |
var options = new Aspose.Html.Saving.XpsSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert EPUB to XPS by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.XpsSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the resulted data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.xps")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Create an instance of the XpsSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.XpsSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing EPUB file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "input.epub")) | |
{ | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
Aspose.Html.Converters.Converter.ConvertEPUB(stream, new Aspose.Html.Saving.XpsSaveOptions(), "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the file | |
using (var document = new HTMLDocument("document.html")) | |
{ | |
// Initialize DocSaveOptions | |
var options = new Aspose.Html.Saving.DocSaveOptions(); | |
// Convert HTML to DOCX | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.docx"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize an HTML document | |
using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello World!!</span>", ".")) | |
{ | |
// Convert HTML to DOCX by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.DocSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.docx")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prepare an HTML code and save it to the file | |
var code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Set A5 as a page-size | |
var options = new Aspose.Html.Saving.DocSaveOptions | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f)) | |
} | |
} | |
}; | |
// Convert HTML document to DOCX | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Invoke the ConvertHTML method to convert the HTML to DOCX. | |
Aspose.Html.Converters.Converter.ConvertHTML(@"<span>Hello World!!</span>", ".", new Aspose.Html.Saving.DocSaveOptions(), "output.docx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp); | |
// Convert HTML to BMP | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.bmp"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Gif); | |
// Convert HTML to GIF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.gif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg); | |
// Convert HTML to JPG | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png); | |
// Convert HTML to PNG | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the html file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Tiff); | |
// Convert HTML to TIFF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.tiff"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize an HTML document | |
using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello</span> <span>World!!</span>", ".")) | |
{ | |
// Convert HTML to Image by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.jpg")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Set up the page-size 3000x1000 pixels and change the background color to green | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg) | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Call the ConvertHTML to convert 'document.html' into jpeg image | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Invoke the ConvertHTML method to convert the HTML code to image. | |
Aspose.Html.Converters.Converter.ConvertHTML(@"<span>Hello</span> <span>World!!</span>", ".", new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), "output.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = "<h1>Header 1</h1>" + | |
"<h2>Header 2</h2>" + | |
"<p>Hello World!!</p>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Call ConvertHTML method to convert HTML to Markdown. | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", Aspose.Html.Saving.MarkdownSaveOptions.Git, "output.md"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = "text<div markdown='inline'><code>text</code></div>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Call ConvertHTML method to convert HTML to Markdown. | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", new Aspose.Html.Saving.MarkdownSaveOptions(), "output.md"); | |
// Output file will contain: text\r\n<div markdown="inline"><code>text</code></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = "<h1>Header 1</h1>" + | |
"<h2>Header 2</h2>" + | |
"<p>Hello World!!</p>" + | |
"<a href='aspose.com'>aspose</a>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of SaveOptions and set up the rule: | |
// - only <a> and <p> elements will be converted to markdown. | |
var options = new Aspose.Html.Saving.MarkdownSaveOptions(); | |
options.Features = Aspose.Html.Saving.MarkdownFeatures.Link | Aspose.Html.Saving.MarkdownFeatures.AutomaticParagraph; | |
// Call the ConvertHTML method to convert the HTML to Markdown. | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.md"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = "<h1>Header 1</h1>" + | |
"<h2>Header 2</h2>" + | |
"<p>Hello World!!</p>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Call ConvertHTML method to convert HTML to Markdown. | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", new Aspose.Html.Saving.MarkdownSaveOptions(), "output.md"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the file | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize MHTMLSaveOptions | |
var options = new Aspose.Html.Saving.MHTMLSaveOptions(); | |
// Convert HTML to MHT | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.mht"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code with a link to another file and save it to the file as 'document.html' | |
var code = "<span>Hello World!!</span> " + | |
"<a href='document2.html'>click</a>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Prepare an HTML code and save it to the file as 'document2.html' | |
code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document2.html", code); | |
// Change the value of the resource linking depth to 1 in order to convert document with directly linked resources. | |
var options = new Aspose.Html.Saving.MHTMLSaveOptions() | |
{ | |
ResourceHandlingOptions = | |
{ | |
MaxHandlingDepth = 1 | |
} | |
}; | |
// Convert HTML to MHT | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.mht"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Invoke the ConvertHTML method to convert the HTML to MHT. | |
Aspose.Html.Converters.Converter.ConvertHTML(@"<span>Hello World!!</span>", ".", new Aspose.Html.Saving.MHTMLSaveOptions(), "output.mht"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the file | |
using (var document = new HTMLDocument("document.html")) | |
{ | |
// Initialize PdfSaveOptions | |
var options = new Aspose.Html.Saving.PdfSaveOptions(); | |
// Convert HTML to PDF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize an HTML document | |
using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello World!!</span>", ".")) | |
{ | |
// Convert HTML to PDF by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.pdf")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Set A5 as a page-size and change the background color to green | |
var options = new Aspose.Html.Saving.PdfSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Convert HTML document to PDF | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Invoke the ConvertHTML method to convert the HTML to PDF. | |
Aspose.Html.Converters.Converter.ConvertHTML(@"<span>Hello World!!</span>", ".", new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Initialize an HTML document from the file | |
using (var document = new HTMLDocument("document.html")) | |
{ | |
// Initialize PdfSaveOptions | |
var options = new Aspose.Html.Saving.XpsSaveOptions(); | |
// Convert HTML to XPS | |
Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize an HTML document | |
using (var document = new Aspose.Html.HTMLDocument(@"<span>Hello World!!</span>", ".")) | |
{ | |
// Convert HTML to XPS by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.XpsSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.xps")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file | |
var code = @"<span>Hello</span> <span>World!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Set A5 as a page-size and change the background color to green | |
var options = new Aspose.Html.Saving.XpsSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Convert HTML document to XPS | |
Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.xps"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Invoke the ConvertHTML method to convert the HTML to XPS. | |
Aspose.Html.Converters.Converter.ConvertHTML(@"<span>Hello World!!</span>", ".", new Aspose.Html.Saving.XpsSaveOptions(), "output.xps"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a simple Markdown example | |
var code = "### Hello World" + | |
"\r\n" + | |
"[visit applications](https://products.aspose.app/html/family)"; | |
// Create a Markdown file | |
System.IO.File.WriteAllText("document.md", code); | |
// Convert Markdown to HTML document | |
using (HTMLDocument document = Aspose.Html.Converters.Converter.ConvertMarkdown("document.md")) | |
{ | |
// Convert HTML document to PNG image file format | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png), "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a simple Markdown example | |
var code = "### Hello World" + | |
"\r\n" + | |
"[visit applications](https://products.aspose.app/html/family)"; | |
// Create a Markdown file | |
System.IO.File.WriteAllText("document.md", code); | |
// Convert Markdown to HTML document | |
Aspose.Html.Converters.Converter.ConvertMarkdown("document.md", "document.html"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp); | |
// Call the ConvertMHTML method to convert the MHTML file to BMP. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.bmp"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Gif); | |
// Call the ConvertMHTML method to convert the MHTML file to GIF. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.gif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg); | |
// Call the ConvertMHTML method to convert the MHTML file to JPG. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png); | |
// Call the ConvertMHTML method to convert the MHTML file to PNG. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Tiff); | |
// Call the ConvertMHTML method to convert the MHTML file to TIFF. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.tiff"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert MHTML to Image by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), | |
streamProvider); | |
// Get access to the memory streams that contain the resulted data | |
for (int i = 0; i < streamProvider.Streams.Count; i++) | |
{ | |
var memory = streamProvider.Streams[i]; | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the page to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create($"page_{i + 1}.jpg")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Initailize the ImageSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg) | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Call the ConvertMHTML method to convert the MHTML file to JPG. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Call the ConvertMHTML method to convert the MHTML file to image. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of PdfSaveOptions. | |
var options = new Aspose.Html.Saving.PdfSaveOptions(); | |
// Call the ConvertMHTML method to convert the MHTML to PDF. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert MHTML to PDF by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the resulted data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.pdf")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of the PdfSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.PdfSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertMHTML method to convert the MHTML to PDF. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Call the ConvertMHTML method to convert the MHTML to PDF. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of XpsSaveOptions. | |
var options = new Aspose.Html.Saving.XpsSaveOptions(); | |
// Call the ConvertMHTML method to convert the MHTML to XPS. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Convert MHTML to XPS by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.XpsSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the resulted data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.xps")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Create an instance of the XpsSaveOptions with a custom page-size and a background-color. | |
var options = new Aspose.Html.Saving.XpsSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertMHTML method to convert the MHTML to XPS. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Open an existing MHTML file for reading. | |
using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht")) | |
{ | |
// Call the ConvertMHTML method to convert the MHTML to XPS. | |
Aspose.Html.Converters.Converter.ConvertMHTML(stream, new Aspose.Html.Saving.XpsSaveOptions(), "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Bmp); | |
// Convert HTML to BMP | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.bmp"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Gif); | |
// Convert HTML to GIF | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.gif"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg); | |
// Convert HTML to JPG | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png); | |
// Convert HTML to PNG | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.png"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize ImageSaveOptions | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Tiff); | |
// Convert HTML to TIFF | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.tiff"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Initialize the SVG document | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument(code, ".")) | |
{ | |
// Convert SVG to Image by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertSVG(document, new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.jpg")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Set up the page-size to 3000x1000 pixels and change the background color. | |
var options = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg) | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.AliceBlue, | |
}; | |
// Call the ConvertSVG to convert 'document.html' into jpeg image | |
Aspose.Html.Converters.Converter.ConvertSVG("document.svg", options, "output.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Invoke the ConvertSVG method to convert the SVG code to image. | |
Aspose.Html.Converters.Converter.ConvertSVG(code, ".", new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg), "output.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize PdfSaveOptions. | |
var options = new Aspose.Html.Saving.PdfSaveOptions(); | |
// Convert HTML to PDF | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Prepare an SVG code | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Initialize an SVG document | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument(code, ".")) | |
{ | |
// Convert SVG to PDF by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertSVG(document, new Aspose.Html.Saving.PdfSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.pdf")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Set A5 as a page-size and change the background color to green | |
var options = new Aspose.Html.Saving.PdfSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Convert SVG document to PDF | |
Aspose.Html.Converters.Converter.ConvertSVG("document.svg", options, "output.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Call the ConvertSVG method to convert the SVG code to PDF. | |
Aspose.Html.Converters.Converter.ConvertSVG(code, ".", new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Initialize an SVG document from the svg file. | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg")) | |
{ | |
// Initialize XpsSaveOptions. | |
var options = new Aspose.Html.Saving.XpsSaveOptions(); | |
// Convert SVG to XPS | |
Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.xps"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of MemoryStreamProvider | |
using (var streamProvider = new MemoryStreamProvider()) | |
{ | |
// Prepare an SVG code | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Initialize an SVG document | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument(code, ".")) | |
{ | |
// Convert SVG to XPS by using the MemoryStreamProvider | |
Aspose.Html.Converters.Converter.ConvertSVG(document, new Aspose.Html.Saving.XpsSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the resulted data | |
var memory = streamProvider.Streams.First(); | |
memory.Seek(0, System.IO.SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (System.IO.FileStream fs = System.IO.File.Create("output.xps")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code and save it to the file. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
System.IO.File.WriteAllText("document.svg", code); | |
// Set A5 as a page-size and change the background color to green | |
var options = new Aspose.Html.Saving.XpsSaveOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page() | |
{ | |
Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f)) | |
} | |
}, | |
BackgroundColor = System.Drawing.Color.Green, | |
}; | |
// Convert SVG document to XPS | |
Aspose.Html.Converters.Converter.ConvertSVG("document.svg", options, "output.xps"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code. | |
var code = "<svg xmlns='http://www.w3.org/2000/svg'>" + | |
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" + | |
"</svg>"; | |
// Invoke the ConvertSVG method to convert the SVG code to image. | |
Aspose.Html.Converters.Converter.ConvertSVG(code, ".", new Aspose.Html.Saving.XpsSaveOptions(), "output.xps"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<style> | |
div { page-break-after: always; } | |
</style> | |
<div style='border: 1px solid red; width: 400px'>First Page</div> | |
<div style='border: 1px solid red; width: 600px'>Second Page</div> | |
"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the instance of Rendering Options and set a custom page-size | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions(); | |
options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(500, 200)); | |
// Enable auto-adjusting for the page size | |
options.PageSetup.AdjustToWidestPage = true; | |
// Create the PDF Device and specify options and output file | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code1 = @"<br><span style='color: green'>Hello World!!</span>"; | |
var code2 = @"<br><span style='color: blue'>Hello World!!</span>"; | |
var code3 = @"<br><span style='color: red'>Hello World!!</span>"; | |
// Create three HTML documents to merge later | |
using (var document1 = new Aspose.Html.HTMLDocument(code1, ".")) | |
using (var document2 = new Aspose.Html.HTMLDocument(code2, ".")) | |
using (var document3 = new Aspose.Html.HTMLDocument(code3, ".")) | |
{ | |
// Create an instance of HTML Renderer | |
using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer()) | |
{ | |
// Create an instance of PDF device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf")) | |
{ | |
// Merge all HTML documents into PDF | |
renderer.Render(device, document1, document2, document3); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @" | |
<script> | |
var count = 0; | |
setInterval(function() | |
{ | |
var element = document.createElement('div'); | |
var message = (++count) + '. ' + 'Hello World!!'; | |
var text = document.createTextNode(message); | |
element.appendChild(text); | |
document.body.appendChild(element); | |
}, 1000); | |
</script> | |
"; | |
// Initialize an HTML document based on prepared HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create an instance of HTML Renderer | |
using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer()) | |
{ | |
// Create an instance of PDF device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf")) | |
{ | |
// Render HTML to PDF | |
renderer.Render(device, System.TimeSpan.FromSeconds(5), document); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<p>Hello World!!</p>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of HTML document | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Initialize options with 'cyan' as a background-color | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions() | |
{ | |
BackgroundColor = System.Drawing.Color.Cyan | |
}; | |
// Create an instance of PDF device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<div>Hello World!!</div>"; | |
// Initialize an instance of HTML document based on prepared code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create an instance of Rendering Options | |
var options = new Aspose.Html.Rendering.Image.ImageRenderingOptions() | |
{ | |
Format = Aspose.Html.Rendering.Image.ImageFormat.Jpeg, | |
// Disable smoothing mode | |
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None, | |
// Set the image resolution as 75 dpi | |
VerticalResolution = Aspose.Html.Drawing.Resolution.FromDotsPerInch(75), | |
HorizontalResolution = Aspose.Html.Drawing.Resolution.FromDotsPerInch(75), | |
}; | |
// Create an instance of Image Device | |
using (var device = new Aspose.Html.Rendering.Image.ImageDevice(options, "output.jpg")) | |
{ | |
// Render HTML to Image | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<style>div { page-break-after: always; }</style> | |
<div>First Page</div> | |
<div>Second Page</div> | |
<div>Third Page</div> | |
<div>Fourth Page</div>"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the instance of Rendering Options and set a custom page-size | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions(); | |
options.PageSetup.SetLeftRightPage( | |
new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 200)), | |
new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(400, 100)) | |
); | |
// Create the PDF Device and specify options and output file | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<span>Hello World!!</span>"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the PDF Device and specify the output file to render | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<div>Hello World!!</div>"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the instance of Rendering Options | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions(); | |
// Set the permissions to the file | |
options.Encryption = new Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo( | |
"user_pwd", | |
"owner_pwd", | |
Aspose.Html.Rendering.Pdf.Encryption.PdfPermissions.PrintDocument, | |
Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionAlgorithm.RC4_128); | |
// Create the PDF Device and specify options and output file | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<span>Hello World!!</span>"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the instance of PdfRenderingOptions and set a custom page-size | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Aspose.Html.Drawing.Page( | |
new Aspose.Html.Drawing.Size( | |
Aspose.Html.Drawing.Length.FromInches(5), | |
Aspose.Html.Drawing.Length.FromInches(2))) | |
} | |
}; | |
// Create the PDF Device and specify options and output file | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @" | |
<style> | |
p | |
{ | |
background: blue; | |
} | |
@media(min-resolution: 300dpi) | |
{ | |
p | |
{ | |
/* high resolution screen color */ | |
background: green | |
} | |
} | |
</style> | |
<p>Hello World!!</p>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of HTML document | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Create options for low-resolution screens | |
var options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions() | |
{ | |
HorizontalResolution = 50, | |
VerticalResolution = 50 | |
}; | |
// Create an instance of PDF device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output_resolution_50.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
// Create options for high-resolution screens | |
options = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions() | |
{ | |
HorizontalResolution = 300, | |
VerticalResolution = 300 | |
}; | |
// Create an instance of PDF device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice(options, "output_resolution_300.pdf")) | |
{ | |
// Render HTML to PDF | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var code = @"<span>Hello World!!</span>"; | |
// Initialize the HTML document from the HTML code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Create the instance of XpsRenderingOptions and set a custom page-size | |
var options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions(); | |
options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page( | |
new Aspose.Html.Drawing.Size( | |
Aspose.Html.Drawing.Length.FromInches(5), | |
Aspose.Html.Drawing.Length.FromInches(2))); | |
// Create the XPS Device and specify options and output file | |
using (var device = new Aspose.Html.Rendering.Xps.XpsDevice(options, "output.xps")) | |
{ | |
// Render HTML to XPS | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a JSON data-source and save it to the file. | |
var data = @"{ | |
'FirstName': 'John', | |
'LastName': 'Smith', | |
'Address': { | |
'City': 'Dallas', | |
'Street': 'Austin rd.', | |
'Number': '200' | |
} | |
}"; | |
System.IO.File.WriteAllText("data-source.json", data); | |
// Prepare an HTML Template and save it to the file. | |
var template = @" | |
<table border=1> | |
<tr> | |
<th>Person</th> | |
<th>Address</th> | |
</tr> | |
<tr> | |
<td>{{FirstName}} {{LastName}}</td> | |
<td>{{Address.Street}} {{Address.Number}}, {{Address.City}}</td> | |
</tr> | |
</table> | |
"; | |
System.IO.File.WriteAllText("template.html", template); | |
// Invoke Converter.ConvertTemplate in order to populate 'template.html' with the data-source from 'data-source.json' file | |
Aspose.Html.Converters.Converter.ConvertTemplate("template.html", new Aspose.Html.Converters.TemplateData("data-source.json"), new Aspose.Html.Loading.TemplateLoadOptions(), "document.html"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
class MemoryStreamProvider : Aspose.Html.IO.ICreateStreamProvider | |
{ | |
// List of MemoryStream objects created during the document rendering | |
public List<System.IO.MemoryStream> Streams { get; } = new List<System.IO.MemoryStream>(); | |
public System.IO.Stream GetStream(string name, string extension) | |
{ | |
// This method is called when the only one output stream is required, for instance for XPS, PDF or TIFF formats. | |
System.IO.MemoryStream result = new System.IO.MemoryStream(); | |
Streams.Add(result); | |
return result; | |
} | |
public System.IO.Stream GetStream(string name, string extension, int page) | |
{ | |
// This method is called when the creation of multiple output streams are required. For instance during the rendering HTML to list of the image files (JPG, PNG, etc.) | |
System.IO.MemoryStream result = new System.IO.MemoryStream(); | |
Streams.Add(result); | |
return result; | |
} | |
public void ReleaseStream(System.IO.Stream stream) | |
{ | |
// Here You can release the stream filled with data and, for instance, flush it to the hard-drive | |
} | |
public void Dispose() | |
{ | |
// Releasing resources | |
foreach (var stream in Streams) | |
stream.Dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", "about:blank")) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", ".")) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument(dataDir+"input.html")) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("http://your.site.com/")) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument(new Url("http://your.site.com/"))) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// do some actions over the document here... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (MemoryStream mem = new MemoryStream()) | |
using (StreamWriter sw = new StreamWriter(mem)) | |
{ | |
sw.Write("<p>my first paragraph</p>"); | |
// It is important to set the position to the beginning, since HTMLDocument starts the reading exactly from the current position within the stream. | |
sw.Flush(); | |
mem.Seek(0, SeekOrigin.Begin); | |
using (var document = new Aspose.Html.HTMLDocument(mem, "about:blank")) | |
{ | |
// do some actions over the document here... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
String outputHtml = dataDir + "SimpleDocument.html"; | |
// Create an instance of HTMLDocument | |
var document = new HTMLDocument(); | |
// Add image | |
if (document.CreateElement("img") is HTMLImageElement img) | |
{ | |
img.Src = "http://via.placeholder.com/400x200"; | |
img.Alt = "Placeholder 400x200"; | |
img.Title = "Placeholder image"; | |
document.Body.AppendChild(img); | |
} | |
// Add ordered list | |
var orderedListElement = document.CreateElement("ol") as HTMLOListElement; | |
for (int i = 0; i < 10; i++) | |
{ | |
var listItem = document.CreateElement("li") as HTMLLIElement; | |
listItem.TextContent = $" List Item {i + 1}"; | |
orderedListElement.AppendChild(listItem); | |
} | |
document.Body.AppendChild(orderedListElement); | |
// Add table 3x3 | |
var table = document.CreateElement("table") as HTMLTableElement; | |
var tBody = document.CreateElement("tbody") as HTMLTableSectionElement; | |
for (var i = 0; i < 3; i++) | |
{ | |
var row = document.CreateElement("tr") as HTMLTableRowElement; | |
row.Id = "trow_" + i; | |
for (var j = 0; j < 3; j++) | |
{ | |
var cell = document.CreateElement("td") as HTMLTableCellElement; | |
cell.Id = $"cell{i}_{j}"; | |
cell.TextContent = "Cell " + j; | |
row.AppendChild(cell); | |
} | |
tBody.AppendChild(row); | |
} | |
table.AppendChild(tBody); | |
document.Body.AppendChild(table); | |
//Save the document to disk | |
document.Save(outputHtml); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<p>paragraph</p><div>some element to remove</div>", "about:blank")) | |
{ | |
var body = document.Body; | |
// Get "div" element | |
var div = (Aspose.Html.HTMLDivElement)body.GetElementsByTagName("div").First(); | |
// Remove found element | |
body.RemoveChild(div); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
var body = document.Body; | |
// Create paragraph element | |
var p = (Aspose.Html.HTMLParagraphElement)document.CreateElement("p"); | |
// Set custom attribute | |
p.SetAttribute("id", "my-paragraph"); | |
// Create text node | |
var text = document.CreateTextNode("my first paragraph"); | |
// Attach text to the paragraph | |
p.AppendChild(text); | |
// Attach paragraph to the document body | |
body.AppendChild(p); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<p>paragraph</p><div>some element to remove</div>", "about:blank")) | |
{ | |
var body = document.Body; | |
// Get "div" element | |
var div = (Aspose.Html.HTMLDivElement)body.GetElementsByTagName("div").First(); | |
// Remove found element | |
body.RemoveChild(div); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: red; }</style><p>my first paragraph</p>", "about:blank")) | |
{ | |
// Get the element to inspect | |
var element = document.GetElementsByTagName("p")[0]; | |
// Get the CSS view object | |
var view = (Aspose.Html.Dom.Css.IViewCSS)document.Context.Window; | |
// Get the computed style of the element | |
var declaration = view.GetComputedStyle(element); | |
// Get "color" property value | |
System.Console.WriteLine(declaration.Color); // rgb(255, 0, 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: red; }</style><p>my first paragraph</p>", "about:blank")) | |
{ | |
// Get the element to edit | |
var element = (Aspose.Html.HTMLElement)document.GetElementsByTagName("p")[0]; | |
// Get the CSS view object | |
var view = (Aspose.Html.Dom.Css.IViewCSS)document.Context.Window; | |
// Get the computed style of the element | |
var declaration = view.GetComputedStyle(element); | |
// Set green color | |
element.Style.Color = "green"; | |
// Get "color" property value | |
System.Console.WriteLine(declaration.Color); // rgb(0, 128, 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Get body element | |
var body = document.Body; | |
// Set content of the body element | |
body.InnerHTML = "<p>paragraph</p>"; | |
// Move to the first child | |
var node = body.FirstChild; | |
System.Console.WriteLine(node.LocalName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
String InputHtml = dataDir + "input.html"; | |
using (FileStream fs = File.Create(InputHtml)) | |
using (StreamWriter sw = new StreamWriter(fs)) | |
{ | |
// Write sample HTML tags to HTML file | |
sw.Write(@"<p>this is a simple text"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
var document = new HTMLDocument(); | |
// subscribe to the event 'OnReadyStateChange' that will be fired once document is completely loaded | |
document.OnReadyStateChange += (sender, @event) => | |
{ | |
if (document.ReadyState == "complete") | |
{ | |
// manipulate with document here | |
} | |
}; | |
document.Navigate(dataDir + "input.html"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(new Aspose.Html.Url(@"https://www.w3.org/TR/html5/")); | |
// Read children nodes and get length information | |
if (document.Body.ChildNodes.Length == 0) | |
Console.WriteLine("No ChildNodes found..."); | |
// Print Document URI to console. As per information above, it has to be https://www.w3.org/TR/html5/ | |
Console.WriteLine("Print Document URI = " + document.DocumentURI); | |
// Print domain name for remote HTML | |
Console.WriteLine("Domain Name = " + document.Domain); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
String InputHtml = "http://aspose.com/"; | |
// Load HTML file using Url instance | |
Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(new Aspose.Html.Url(InputHtml)); | |
// Print inner HTML of file to console | |
Console.WriteLine(document.Body.InnerHTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Create an empty document | |
using (HTMLDocument document = new HTMLDocument()) | |
{ | |
// Create a Canvas element | |
var canvas = (HTMLCanvasElement)document.CreateElement("canvas"); | |
// Set the canvas size | |
canvas.Width = 300; | |
canvas.Height = 150; | |
// Append created element to the document | |
document.Body.AppendChild(canvas); | |
// Initialize a canvas 2D context | |
var context = (ICanvasRenderingContext2D)canvas.GetContext("2d"); | |
// Prepare a gradient brush | |
var gradient = context.CreateLinearGradient(0, 0, canvas.Width, 0); | |
gradient.AddColorStop(0, "magenta"); | |
gradient.AddColorStop(0.5, "blue"); | |
gradient.AddColorStop(1.0, "red"); | |
// Set the previously prepared brush to the fill and stroke properties | |
context.FillStyle = gradient; | |
context.StrokeStyle = gradient; | |
// Fill a rectange | |
context.FillRect(0, 95, 300, 20); | |
// Write a text | |
context.FillText("Hello World!", 10, 90, 500); | |
// Create an instance of HTML renderer and XPS output device | |
using (var renderer = new HtmlRenderer()) | |
using (var device = new XpsDevice(dataDir + "canvas.xps")) | |
{ | |
// Render the document to the specified device | |
renderer.Render(device, document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
String InputHtml = dataDir + "input.html"; | |
// Create HtmlDocument instance to load existing HTML file | |
Aspose.Html.HTMLDocument document = new Aspose.Html.HTMLDocument(InputHtml); | |
// Print inner HTML of file to console | |
Console.WriteLine(document.Body.InnerHTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<h1>heading text</h1>", "about:blank")) | |
{ | |
// Create corresponding save options | |
var saveOptions = Aspose.Html.Saving.MarkdownSaveOptions.Git; | |
// Save to .md file | |
document.Save(dataDir+ "HTMLToMarkDown_out.md", saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument(@" | |
<link href=""c:\work\style.css"" rel=""stylesheet""> | |
<p>my first paragraph</p>", "about:blank")) | |
{ | |
// Create corresponding save options | |
var saveOptions = new Aspose.Html.Saving.MHTMLSaveOptions(); | |
// Set default resource handling behaviour to "embed" | |
saveOptions.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Embed; | |
// Remove URL restrictions because referenced resource is in another domain | |
saveOptions.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.None; | |
// Save to .mht file | |
document.Save(dataDir + "HtmlToMhtml_out.mht", saveOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", "about:blank")) | |
{ | |
document.Save(dataDir + "SaveToFile_out.html"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<p>my first paragraph</p>", "about:blank")) | |
{ | |
// Create options object | |
Aspose.Html.Saving.HTMLSaveOptions options = new Aspose.Html.Saving.HTMLSaveOptions(); | |
// Set the maximum depth of resource which will be handled. | |
// Depth of 1 means that only resources directly referenced from the saved document will be handled. | |
// Setting this property to -1 will lead to handling of all resources. | |
// Default value is 3 | |
options.ResourceHandlingOptions.MaxHandlingDepth = 1; | |
// This property is used to set restriction applied to handlers of external resources. | |
// SameHost means that only resources located at the same host will be saved. | |
options.ResourceHandlingOptions.UrlRestriction = Aspose.Html.Saving.UrlRestriction.SameHost; | |
// This property is used to setup processing behaviour of any type of resource. | |
// ResourceHandling.Save means all resources will be saved to the output folder | |
options.ResourceHandlingOptions.Default = Aspose.Html.Saving.ResourceHandling.Save; | |
// This property is used to set up processing behaviour of particular 'application/javascript' mime type. | |
// In our case all scripts will be skipped during saving | |
options.ResourceHandlingOptions.JavaScript = Aspose.Html.Saving.ResourceHandling.Discard; | |
// Save the document | |
document.Save(dataDir + "SaveUsingHTMLSaveOptions_out.html", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// set metered public and private keys | |
Aspose.Html.Metered metered = new Aspose.Html.Metered(); | |
// Access the setMeteredKey property and pass public and private keys as parameters | |
metered.SetMeteredKey("*****", "*****"); | |
// Load the document from disk. | |
HTMLDocument document = new HTMLDocument(dataDir + "input.html"); | |
// Print inner HTML of file to console | |
Console.WriteLine(document.Body.InnerHTML); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL of the video you want to download | |
string url = "https://www.youtube.com/watch?v=JlKF7z8ODIo"; | |
// File name for downloading video | |
string filename = "HTML-to-Markdown"; | |
// Initialize an instance of MultimediaScraper class | |
using var multimediaScraper = new Aspose.Html.DataScraping.MultimediaScraping.MultimediaScraper(); | |
// Create a multimedia object that include information from the URL | |
using (var multimedia = multimediaScraper.GetMultimedia(url)) | |
{ | |
// Get a videoInfo object | |
var videoInfo = multimedia.CollectVideoInfo(); | |
// Get the first element from the formats collection with minimal bitrate and present audio and video codecs | |
var format = videoInfo.Formats.OrderBy(f => f.Bitrate).First(f => f.AudioCodec != null && f.VideoCodec != null); | |
// Get the extension for the output file | |
var ext = string.IsNullOrEmpty(format.Extension) ? "mp4" : format.Extension; | |
// Get the full file path for the output file | |
var filePath = System.IO.Path.Combine(OutputDir, filename + "." + ext); | |
// Download video | |
multimedia.Download(format, filePath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL of the video you want to extract data from | |
string url = "https://www.youtube.com/watch?v=0Ww_tCjxsYc"; | |
// Initialize an instance of MultimediaScraper class | |
using (var multimediaScraper = new Aspose.Html.DataScraping.MultimediaScraping.MultimediaScraper()) | |
// Create a multimedia object that include information from the URL | |
using var multimedia = multimediaScraper.GetMultimedia(url); | |
// Get a videoInfo object | |
var videoInfo = multimedia.CollectVideoInfo(); | |
// Show video format information from the collection of available formats | |
int i = 0; | |
foreach (var videoFormatInfo in videoInfo.Formats.OrderBy(f => f.Bitrate)) | |
{ | |
Console.WriteLine("Format #{0}", ++i); | |
Console.WriteLine(" Bitrate: {0}", videoFormatInfo.Bitrate?.ToString() ?? "[null]"); | |
Console.WriteLine(" Audio Codec: {0}", videoFormatInfo.AudioCodec ?? "[null]"); | |
Console.WriteLine(" Video Codec: {0}", videoFormatInfo.VideoCodec ?? "[null]"); | |
Console.WriteLine(" Width: {0}", videoFormatInfo.Width?.ToString() ?? "[null]"); | |
Console.WriteLine(" Height: {0}", videoFormatInfo.Height?.ToString() ?? "[null]"); | |
Console.WriteLine(" Extension: {0}", videoFormatInfo.Extension ?? "[null]"); | |
Console.WriteLine(" File Size: {0}", videoFormatInfo.FileSize?.ToString() ?? "[null]"); | |
Console.WriteLine(" FPS: {0}", videoFormatInfo.FPS?.ToString() ?? "[null]"); | |
Console.WriteLine(" Sampling Rate: {0}", videoFormatInfo.SamplingRate?.ToString() ?? "[null]"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL of the video you want to extract data from | |
string url = "https://www.youtube.com/watch?v=cTnbD67vqjo"; | |
// Initialize an instance of the MultimediaScraper class | |
using var multimediaScraper = new Aspose.Html.DataScraping.MultimediaScraping.MultimediaScraper(); | |
// Create a multimedia object that include information from the URL | |
using (var multimedia = multimediaScraper.GetMultimedia(url)) | |
{ | |
// Get a videoInfo object | |
var videoInfo = multimedia.CollectVideoInfo(); | |
// Show information about the video | |
Console.WriteLine("Title: {0}", videoInfo.Title); | |
Console.WriteLine("Description: {0}", videoInfo.Description); | |
Console.WriteLine("Duration: {0}", videoInfo.Duration); | |
Console.WriteLine("Thumbnails count: {0}", videoInfo.Thumbnails.Count); | |
Console.WriteLine("Formats count: {0}", videoInfo.Formats.Count); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare HTML code | |
var code = @" | |
<div class='happy'> | |
<div> | |
<span>Hello</span> | |
</div> | |
</div> | |
<p class='happy'> | |
<span>World!</span> | |
</p> | |
"; | |
// Initialize a document based on the prepared code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Here we create a CSS Selector that extract all elements whose 'class' attribute equals to 'happy' and their child SPAN elements | |
var elements = document.QuerySelectorAll(".happy span"); | |
// Iterate over the resulted list of elements | |
foreach (Aspose.Html.HTMLElement element in elements) | |
{ | |
System.Console.WriteLine(element.InnerHTML); | |
// output: Hello | |
// output: World! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare HTML code | |
var code = @" | |
<p>Hello</p> | |
<img src='image1.png'> | |
<img src='image2.png'> | |
<p>World!</p>"; | |
// Initialize a document based on the prepared code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// To start HTML navigation we need to create an instance of TreeWalker. | |
// The specified parameters mean that it starts walking from the root of the document, iterating all nodes and use our custom implementation of the filter | |
using (var iterator = document.CreateTreeWalker(document, Aspose.Html.Dom.Traversal.Filters.NodeFilter.SHOW_ALL, new OnlyImageFilter())) | |
{ | |
while (iterator.NextNode() != null) | |
{ | |
// Since we are using our own filter, the current node will always be an instance of the HTMLImageElement. | |
// So, we don't need the additional validations here. | |
var image = (Aspose.Html.HTMLImageElement)iterator.CurrentNode; | |
System.Console.WriteLine(image.Src); | |
// output: image1.png | |
// output: image2.png | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
class OnlyImageFilter : Aspose.Html.Dom.Traversal.Filters.NodeFilter | |
{ | |
public override short AcceptNode(Aspose.Html.Dom.Node n) | |
{ | |
// The current filter skips all elements, except IMG elements. | |
return string.Equals("img", n.LocalName) | |
? FILTER_ACCEPT | |
: FILTER_SKIP; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare HTML code | |
var code = @" | |
<div class='happy'> | |
<div> | |
<span>Hello!</span> | |
</div> | |
</div> | |
<p class='happy'> | |
<span>World</span> | |
</p> | |
"; | |
// Initialize a document based on the prepared code | |
using (var document = new Aspose.Html.HTMLDocument(code, ".")) | |
{ | |
// Here we evaluate the XPath expression where we select all child SPAN elements from elements whose 'class' attribute equals to 'happy': | |
var result = document.Evaluate("//*[@class='happy']//span", | |
document, | |
null, | |
Aspose.Html.Dom.XPath.XPathResultType.Any, | |
null); | |
// Iterate over the resulted nodes | |
for (Aspose.Html.Dom.Node node; (node = result.IterateNext()) != null;) | |
{ | |
System.Console.WriteLine(node.TextContent); | |
// output: Hello | |
// output: World! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Initialize configuration object and set up the page-margins for the document | |
Configuration configuration = new Configuration(); | |
configuration.GetService<IUserAgentService>().UserStyleSheet = @" | |
@page | |
{ | |
/* Page margins should be not empty in order to write content inside the margin-boxes */ | |
margin-top: 1cm; | |
margin-left: 2cm; | |
margin-right: 2cm; | |
margin-bottom: 2cm; | |
/* Page counter located at the bottom of the page */ | |
@bottom-right | |
{ | |
-aspose-content: ""Page "" currentPageNumber() "" of "" totalPagesNumber(); | |
color: green; | |
} | |
/* Page title located at the top-center box */ | |
@top-center | |
{ | |
-aspose-content: ""Document's title""; | |
vertical-align: bottom; | |
} | |
}"; | |
// Initialize an empty document | |
using (HTMLDocument document = new HTMLDocument(configuration)) | |
{ | |
// Initialize an output device | |
using (XpsDevice device = new XpsDevice(dataDir + "output_out.xps")) | |
{ | |
// Send the document to the output device | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
var options = new PdfRenderingOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Page(new Size(500, 500), new Margin(50, 50, 50, 50)) | |
}, | |
Encryption = new PdfEncryptionInfo("user", "p@wd", PdfPermissions.PrintDocument, PdfEncryptionAlgorithm.RC4_128) | |
}; | |
using (PdfDevice device = new PdfDevice(options, dataDir + @"document_out.pdf")) | |
{ | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
// Initialize rendering optionss and set jpeg as output format | |
var options = new ImageRenderingOptions(ImageFormat.Jpeg); | |
// Set the size and margin property for all pages. | |
options.PageSetup.AnyPage = new Page(new Size(500, 500), new Margin(50, 50, 50, 50)); | |
// If the document has an element which size is bigger than predefined by user page size output pages will be will be adjusted. | |
options.PageSetup.AdjustToWidestPage = true; | |
using (ImageDevice device = new ImageDevice(options, dataDir + @"document_out.jpg")) | |
{ | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
using (ImageDevice device = new ImageDevice(dataDir + @"document_out.png")) | |
{ | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
using (XpsDevice device = new XpsDevice(new XpsRenderingOptions() | |
{ | |
PageSetup = | |
{ | |
AnyPage = new Page(new Size(500, 500), new Margin(50, 50, 50, 50)) | |
} | |
}, dataDir + @"document_out.xps")) | |
{ | |
document.RenderTo(device); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create the instance of HTML Document | |
var document = new Aspose.Html.HTMLDocument(); | |
// Subscribe to the 'OnLoad' event. | |
// This event will be fired once the document is fully loaded. | |
document.OnLoad += (sender, @event) => | |
{ | |
Console.WriteLine(document.DocumentElement.OuterHTML); | |
Console.WriteLine("Loading is completed. Press any key to continue..."); | |
}; | |
// Navigate asynchronously at the specified Uri | |
document.Navigate("https://html.spec.whatwg.org/multipage/introduction.html"); | |
Console.WriteLine("Waiting for loading..."); | |
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create the instance of HTML Document | |
var document = new Aspose.Html.HTMLDocument(); | |
// Subscribe to the 'ReadyStateChange' event. | |
// This event will be fired during the document loading process. | |
document.OnReadyStateChange += (sender, @event) => | |
{ | |
// Check the value of 'ReadyState' property. | |
// This property is representing the status of the document. For detail information please visit https://www.w3schools.com/jsref/prop_doc_readystate.asp | |
if (document.ReadyState == "complete") | |
{ | |
Console.WriteLine(document.DocumentElement.OuterHTML); | |
Console.WriteLine("Loading is completed. Press any key to continue..."); | |
} | |
}; | |
// Navigate asynchronously at the specified Uri | |
document.Navigate("https://html.spec.whatwg.org/multipage/introduction.html"); | |
Console.WriteLine("Waiting for loading..."); | |
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a 'document.html' file. | |
System.IO.File.WriteAllText("document.html", "Hello World!"); | |
// Load from a 'document.html' file. | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Write the document content to the output stream. | |
Console.WriteLine(document.DocumentElement.OuterHTML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create a memory stream object | |
using (var mem = new System.IO.MemoryStream()) | |
using (var sw = new System.IO.StreamWriter(mem)) | |
{ | |
// Write the HTML Code into memory object | |
sw.Write("<p>Hello World!</p>"); | |
// It is important to set the position to the beginning, since HTMLDocument starts the reading exactly from the current position within the stream. | |
sw.Flush(); | |
mem.Seek(0, System.IO.SeekOrigin.Begin); | |
// Initialize document from the string variable | |
using (var document = new Aspose.Html.HTMLDocument(mem, ".")) | |
{ | |
// Save the document to disk. | |
document.Save("document.html"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Initialize an empty HTML Document. | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Create a text element and add it to the document | |
var text = document.CreateTextNode("Hello World!"); | |
document.Body.AppendChild(text); | |
// Save the document to disk. | |
document.Save("document.html"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var html_code = "<p>Hello World!</p>"; | |
// Initialize document from the string variable | |
using (var document = new Aspose.Html.HTMLDocument(html_code, ".")) | |
{ | |
// Save the document to disk. | |
document.Save("document.html"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Load a document from 'https://html.spec.whatwg.org/multipage/introduction.html' web page | |
using (var document = new Aspose.Html.HTMLDocument("https://html.spec.whatwg.org/multipage/introduction.html")) | |
{ | |
// Write the document content to the output stream. | |
Console.WriteLine(document.DocumentElement.OuterHTML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Initialize the SVG Document from the string object | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", ".")) | |
{ | |
// Write the document content to the output stream. | |
Console.WriteLine(document.DocumentElement.OuterHTML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of HTML Document with specified content | |
var content = "<style>p { color: red; }</style><p>Hello World!</p>"; | |
using (var document = new Aspose.Html.HTMLDocument(content, ".")) | |
{ | |
// Find the paragraph element to inspect the styles | |
var paragraph = (Aspose.Html.HTMLElement)document.GetElementsByTagName("p").First(); | |
// Get the reference to the IViewCSS interface. | |
var view = (Aspose.Html.Dom.Css.IViewCSS)document.Context.Window; | |
// Get the calculated style value for the paragraph node | |
var declaration = view.GetComputedStyle(paragraph); | |
// Read the "color" property value out of the style declaration object | |
System.Console.WriteLine(declaration.Color); // rgb(255, 0, 0) | |
// Set the green color to the paragraph | |
paragraph.Style.Color = "green"; | |
// Create the instance of the PDF output device and render the document into this device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf")) | |
document.RenderTo(device); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create the instance of HTML Document | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Create the style element and assign the green color for all elements with class-name equals 'gr'. | |
var style = document.CreateElement("style"); | |
style.TextContent = ".gr { color: green }"; | |
// Find the document header element and append style element to the header | |
var head = document.GetElementsByTagName("head").First(); | |
head.AppendChild(style); | |
// Create the paragraph element with class-name 'gr'. | |
var p = (Aspose.Html.HTMLParagraphElement)document.CreateElement("p"); | |
p.ClassName = "gr"; | |
// Create the text node | |
var text = document.CreateTextNode("Hello World!!"); | |
// Append the text node to the paragraph | |
p.AppendChild(text); | |
// Append the paragraph to the document body element | |
document.Body.AppendChild(p); | |
// Create the instance of the PDF output device and render the document into this device | |
using (var device = new Aspose.Html.Rendering.Pdf.PdfDevice("output.pdf")) | |
document.RenderTo(device); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Create an instance of HTML Document | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Write the content of the HTML document into the console output | |
Console.WriteLine(document.DocumentElement.OuterHTML); // output: <html><head></head><body></body></html> | |
// Set content of the body element | |
document.Body.InnerHTML = "<p>Hello World!!</p>"; | |
// Write the content of the HTML document into the console output | |
Console.WriteLine(document.DocumentElement.OuterHTML); // output: <html><head></head><body><p>Hello World!!</p></body></html> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code with missing image file | |
var code = @"<img src='missing.jpg'>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of Configuration | |
using (var configuration = new Aspose.Html.Configuration()) | |
{ | |
// Add ErrorMessageHandler to the chain of existing message handlers | |
var network = configuration.GetService<Aspose.Html.Services.INetworkService>(); | |
network.MessageHandlers.Add(new LogMessageHandler()); | |
// Initialize an HTML document with specified configuration | |
// During the document loading, the application will try to load the image and we will see the result of this operation in the console. | |
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration)) | |
{ | |
// Convert HTML to PNG | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(), "output.png"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = "<span>Hello World!!</span> " + | |
"<script>document.write('Have a nice day!');</script>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of Configuration | |
using (var configuration = new Aspose.Html.Configuration()) | |
{ | |
// Mark 'scripts' as an untrusted resource | |
configuration.Security |= Aspose.Html.Sandbox.Scripts; | |
// Initialize an HTML document with specified configuration | |
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration)) | |
{ | |
// Convert HTML to PDF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code with endless loop | |
var code = @"<script>while(true){}</script>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of Configuration | |
using (var configuration = new Aspose.Html.Configuration()) | |
{ | |
// Limit JS execution time to 10 seconds | |
var runtime = configuration.GetService<Aspose.Html.Services.IRuntimeService>(); | |
runtime.JavaScriptTimeout = TimeSpan.FromSeconds(10); | |
// Initialize an HTML document with specified configuration | |
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration)) | |
{ | |
// Wait until all scripts are finished/canceled and convert HTML to PNG | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.ImageSaveOptions(), "output.png"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
/// <summary> | |
/// This message handler logs all failed requests to the console. | |
/// </summary> | |
public class LogMessageHandler : Aspose.Html.Net.MessageHandler | |
{ | |
public override void Invoke(Aspose.Html.Net.INetworkOperationContext context) | |
{ | |
// Check whether response is OK | |
if (context.Response.StatusCode != System.Net.HttpStatusCode.OK) | |
{ | |
// Log information to console | |
System.Console.WriteLine("File Not Found: " + context.Request.RequestUri); | |
} | |
// Invoke the next message handler in the chain. | |
Next(context); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Configuration | |
var configuration = new Aspose.Html.Configuration(); | |
// Get the IUserAgentService | |
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>(); | |
// Set ISO-8859-1 encoding to parse the document | |
userAgent.CharSet = "ISO-8859-1"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an instance of Configuration | |
var configuration = new Aspose.Html.Configuration(); | |
// Get the IUserAgentService | |
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>(); | |
// Set a custom font folder path | |
userAgent.FontsSettings.SetFontsLookupFolder(@".\fonts\"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code and save it to the file. | |
var code = @"<span>Hello World!!!</span>"; | |
System.IO.File.WriteAllText("document.html", code); | |
// Create an instance of Configuration | |
using (var configuration = new Aspose.Html.Configuration()) | |
{ | |
// Get the IUserAgentService | |
var userAgent = configuration.GetService<Aspose.Html.Services.IUserAgentService>(); | |
// Set the custom color to the SPAN element | |
userAgent.UserStyleSheet = "span { color: green; }"; | |
// Initialize an HTML document with specified configuration | |
using (var document = new Aspose.Html.HTMLDocument("document.html", configuration)) | |
{ | |
// Convert HTML to PDF | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new Aspose.Html.Saving.PdfSaveOptions(), "output.pdf"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Initialize an empty HTML Document. | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Create a text element and add it to the document | |
var text = document.CreateTextNode("Hello World!"); | |
document.Body.AppendChild(text); | |
// Save the HTML to the file on disk. | |
document.Save("document.html"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an HTML code | |
var html_code = "<H2>Hello World!</H2>"; | |
// Initialize document from the string variable | |
using (var document = new Aspose.Html.HTMLDocument(html_code, ".")) | |
{ | |
// Save the document as a Markdown file. | |
document.Save("document.md", Aspose.Html.Saving.HTMLSaveFormat.Markdown); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a simple HTML file with a linked document. | |
System.IO.File.WriteAllText("document.html", "<p>Hello World!</p>" + | |
"<a href='linked.html'>linked file</a>"); | |
// Prepare a simple linked HTML file | |
System.IO.File.WriteAllText("linked.html", "<p>Hello linked file!</p>"); | |
// Load 'document.html' into memory | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Save the document | |
document.Save(@".\html-to-file-example\document.mht", Aspose.Html.Saving.HTMLSaveFormat.MHTML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare a simple HTML file with a linked document. | |
System.IO.File.WriteAllText("document.html", "<p>Hello World!</p>" + | |
"<a href='linked.html'>linked file</a>"); | |
// Prepare a simple linked HTML file | |
System.IO.File.WriteAllText("linked.html", "<p>Hello linked file!</p>"); | |
// Load 'document.html' into memory | |
using (var document = new Aspose.Html.HTMLDocument("document.html")) | |
{ | |
// Create Save Options instance | |
var options = new Aspose.Html.Saving.HTMLSaveOptions(); | |
// The following line with value '0' cut off all other linked HTML-files while saving this instance. | |
// If you remove this line or change value to the '1', the 'linked.html' file will be saved as well to the output folder. | |
options.ResourceHandlingOptions.MaxHandlingDepth = 1; | |
// Save the document | |
document.Save(@".\html-to-file-example\document.html", options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// Prepare an SVG code | |
var code = @" | |
<svg xmlns='http://www.w3.org/2000/svg' height='80' width='300'> | |
<g fill='none'> | |
<path stroke='red' d='M5 20 l215 0' /> | |
<path stroke='black' d='M5 40 l215 0' /> | |
<path stroke='blue' d='M5 60 l215 0' /> | |
</g> | |
</svg>"; | |
// Initialize a SVG instance from the content string | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument(code, ".")) | |
{ | |
// Save the SVG file to the disk | |
document.Save("document.svg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Create a custom StreamProvider based on ICreateStreamProvider interface | |
using (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) | |
{ | |
// Create a simple HTML document | |
using (HTMLDocument document = new HTMLDocument()) | |
{ | |
// Add your first 'hello world' to the document. | |
document.Body.AppendChild(document.CreateTextNode("Hello world!!!")); | |
// Convert HTML document to XPS by using the custom StreamProvider | |
Aspose.Html.Converters.Converter.ConvertHTML(document, new XpsSaveOptions(), streamProvider); | |
// Get access to the memory stream that contains the result data | |
var memory = streamProvider.Streams[0]; | |
memory.Seek(0, SeekOrigin.Begin); | |
// Flush the result data to the output file | |
using (FileStream fs = File.Create(dataDir + "output.xps")) | |
{ | |
memory.CopyTo(fs); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. | |
// Create an empty document | |
using (var document = new HTMLDocument()) | |
{ | |
// Create a WaitHandle for purpose described below | |
var @event = new ManualResetEvent(false); | |
// Create an observer instance | |
var observer = new MutationObserver((mutations, mutationObserver) => | |
{ | |
var mutation = mutations[0]; | |
Console.WriteLine(mutation.AddedNodes[0]); | |
@event.Set(); | |
}); | |
// Options for the observer (which mutations to observe) | |
var config = new MutationObserverInit | |
{ | |
ChildList = true, | |
Subtree = true | |
}; | |
// Start observing the target node | |
observer.Observe(document.DocumentElement, config); | |
// An example of user modifications | |
var p = document.CreateElement("p"); | |
document.DocumentElement.AppendChild(p); | |
// Since, mutations are working in the async mode you should wait a bit. We use WaitHandle for this purpose. | |
@event.WaitOne(); | |
// Later, you can stop observing | |
observer.Disconnect(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var fs = File.OpenRead(dataDir + "document.epub")) | |
using (var device = new Aspose.Html.Rendering.Xps.XpsDevice(dataDir + "document_out.xps")) | |
using (var renderer = new Aspose.Html.Rendering.EpubRenderer()) | |
{ | |
renderer.Render(device, fs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
using (HtmlRenderer renderer = new HtmlRenderer()) | |
using (ImageDevice device = new ImageDevice(dataDir + @"document_out.png")) | |
{ | |
renderer.Render(device, document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Create an instance of the HTML document | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Async loading of the external html file | |
document.Navigate( dataDir + "input.html"); | |
// Create a renderer and output device | |
using (HtmlRenderer renderer = new HtmlRenderer()) | |
using (ImageDevice device = new ImageDevice(dataDir + @"document.png")) | |
{ | |
// Delay the rendering indefinitely until there are no scripts or any other internal tasks to execute | |
renderer.Render(device, -1, document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// Create an instance of the HTML document | |
using (var document = new Aspose.Html.HTMLDocument()) | |
{ | |
// Async loading of the external html file | |
document.Navigate(dataDir + "input.html"); | |
// Create a renderer and output device | |
using (HtmlRenderer renderer = new HtmlRenderer()) | |
using (ImageDevice device = new ImageDevice(dataDir + @"document.png")) | |
{ | |
// Delay rendering for 5 seconds | |
// Note: document will be rendered into device if there are no scripts or any internal tasks to execute | |
renderer.Render(device, TimeSpan.FromSeconds(5), document); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var fs = File.OpenRead(dataDir + "document.mht")) | |
using (var device = new Aspose.Html.Rendering.Xps.XpsDevice(dataDir + "document_out.xps")) | |
using (var renderer = new Aspose.Html.Rendering.MhtmlRenderer()) | |
{ | |
renderer.Render(device, fs); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", @"c:\work\")) | |
using (var document2 = new Aspose.Html.HTMLDocument("<style>p { color: blue; }</style><p>my first paragraph</p>", @"c:\work\")) | |
{ | |
using (HtmlRenderer renderer = new HtmlRenderer()) | |
using (XpsDevice device = new XpsDevice(dataDir + @"document_out.xps")) | |
{ | |
renderer.Render(device, document, document2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
string dataDir = RunExamples.GetDataDir_Data(); | |
using (var document = new Aspose.Html.Dom.Svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", @"c:\work\")) | |
{ | |
using (SvgRenderer renderer = new SvgRenderer()) | |
using (ImageDevice device = new ImageDevice(dataDir + @"document_out.png")) | |
{ | |
renderer.Render(device, document); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// HTML template document | |
HTMLDocument templateHtml = new HTMLDocument(dataDir + "HTMLTemplateForJson.html"); | |
//XML data for merging | |
TemplateData data = new TemplateData(dataDir + "JsonTemplate.json"); | |
//Output file path | |
string templateOutput = dataDir + "MergeHTMLWithJson_Output.html"; | |
//Merge HTML tempate with XML data | |
Converter.ConvertTemplate(templateHtml, data, new TemplateLoadOptions(), templateOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET | |
// The path to the documents directory | |
string dataDir = RunExamples.GetDataDir_Data(); | |
// HTML template document | |
HTMLDocument templateHtml = new HTMLDocument(dataDir + "HTMLTemplateforXML.html"); | |
//XML data for merging | |
TemplateData data = new TemplateData(dataDir + "XMLTemplate.xml"); | |
//Output file path | |
string templateOutput = dataDir + "HTMLTemplate_Output.html"; | |
//Merge HTML tempate with XML data | |
Converter.ConvertTemplate(templateHtml, data, new TemplateLoadOptions(), templateOutput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>{{Title}}</title> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<div data_merge="{{#foreach Persons}}"> | |
<p>Name: {{Name}} {{Surname}}</p> | |
<p>Address: {{Address.Number}}, {{Address.Street}}, {{Address.City}}</p> | |
<br/> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Test JSON</title> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<DIV> | |
<P>Name: John Smith</P> | |
<P>Address: 200, Austin rd., Dallas</P> | |
<BR> | |
</DIV> | |
<DIV> | |
<P>Name: Jack Fox</P> | |
<P>Address: 25, Broadway, New York</P> | |
<BR> | |
</DIV> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Title": "Test JSON", | |
"Persons": [ | |
{ | |
"Name": "John", | |
"Surname": "Smith", | |
"Address": { | |
"Number": "200", | |
"Street": "Austin rd.", | |
"City": "Dallas" | |
} | |
}, | |
{ | |
"Name": "Jack", | |
"Surname": "Fox", | |
"Address": { | |
"Number": "25", | |
"Street": "Broadway", | |
"City": "New York" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment