PdfFocusCHtmlOptionsInlineCSS Property |
Gets or sets a value whether to store CSS as inline for the each element using the "style" attribute or embed the whole style sheet inside HTML. Default value: true.
Namespace: SautinSoftAssembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.9.26
Syntax public bool InlineCSS { get; set; }
Public Property InlineCSS As Boolean
Get
Set
Property Value
BooleanExample How to convert multiple PDF files to HTML using C#
using System;
using System.IO;
using System.Linq;
using System.Text;
using SautinSoft;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
ConvertMultiplePdfToHtmls();
}
static void ConvertMultiplePdfToHtmls()
{
string pdfDirectory = Path.GetFullPath(@"..\..\..\");
string[] pdfFiles = Directory.GetFiles(pdfDirectory, "*.pdf");
DirectoryInfo htmlDirectory = new DirectoryInfo(@"htmls");
if (!htmlDirectory.Exists)
htmlDirectory.Create();
PdfFocus f = new PdfFocus();
int success = 0;
int total = 0;
foreach (string pdfFile in pdfFiles)
{
Console.WriteLine("Converting {0} ...", Path.GetFileName(pdfFile));
f.OpenPdf(pdfFile);
total++;
if (f.PageCount > 0)
{
f.HtmlOptions.ImageFolder = htmlDirectory.FullName;
f.HtmlOptions.ImageSubFolder = String.Format("{0}_images", Path.GetFileNameWithoutExtension(pdfFile));
f.HtmlOptions.ImageFileName = "picture";
f.EmbeddedImagesFormat = PdfFocus.eImageFormat.Auto;
f.HtmlOptions.IncludeImageInHtml = false;
string htmlFile = Path.GetFileNameWithoutExtension(pdfFile) + ".html";
string htmlFilePath = Path.Combine(htmlDirectory.FullName, htmlFile);
if (f.ToHtml(htmlFilePath) == 0)
{
success++;
}
}
}
Console.WriteLine("{0} of {1} files converted successfully!", success, total);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlDirectory.FullName) { UseShellExecute = true });
}
static void ConvertMultiplePdfToSingleHtml()
{
string pdfDirectory = Path.GetFullPath(@"..\..\..\");
string htmlFile = "Result.html";
string[] pdfFiles = Directory.GetFiles(pdfDirectory, "*.pdf");
StringBuilder singleHtml = new StringBuilder();
singleHtml.Append("<html>\r\n<head>\r\n");
singleHtml.Append(@"<meta http-equiv = ""Content-Type"" content=""text/html; charset=utf-8"" />");
singleHtml.Append("\r\n</head>\r\n<body>");
PdfFocus f = new PdfFocus();
int success = 0;
int total = 0;
foreach (string pdfFile in pdfFiles)
{
Console.WriteLine("Converting {0} ...", Path.GetFileName(pdfFile));
f.OpenPdf(pdfFile);
total++;
if (f.PageCount > 0)
{
f.HtmlOptions.IncludeImageInHtml = false;
f.HtmlOptions.ImageSubFolder = String.Format("{0}_images", Path.GetFileNameWithoutExtension(pdfFile));
f.HtmlOptions.ImageFileName = "picture";
f.EmbeddedImagesFormat = PdfFocus.eImageFormat.Auto;
f.HtmlOptions.InlineCSS = true;
f.HtmlOptions.ProduceOnlyHtmlBody = true;
string tempHtml = f.ToHtml();
if (!String.IsNullOrEmpty(tempHtml))
{
success++;
singleHtml.Append(tempHtml);
}
}
}
singleHtml.Append("</body></html>");
File.WriteAllText(htmlFile, singleHtml.ToString());
Console.WriteLine("{0} of {1} files converted and merged into {2}!", success, total, Path.GetFileName(htmlFile));
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(htmlFile) { UseShellExecute = true });
}
}
}
How to convert multiple PDF files to HTML using VB.Net
Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Linq
Imports System.Text
Imports SautinSoft
Namespace Sample
Friend Class Sample
Shared Sub Main(ByVal args() As String)
ConvertMultiplePdfToSingleHtml()
End Sub
Private Shared Sub ConvertMultiplePdfToHtmls()
Dim pdfDirectory As String = Path.GetFullPath("..\..\..\")
Dim pdfFiles() As String = Directory.GetFiles(pdfDirectory, "*.pdf")
Dim htmlDirectory As New DirectoryInfo("htmls")
If Not htmlDirectory.Exists Then
htmlDirectory.Create()
End If
Dim f As New PdfFocus()
Dim success As Integer = 0
Dim total As Integer = 0
For Each pdfFile As String In pdfFiles
Console.WriteLine("Converting {0} ...", Path.GetFileName(pdfFile))
f.OpenPdf(pdfFile)
total += 1
If f.PageCount > 0 Then
f.HtmlOptions.ImageFolder = htmlDirectory.FullName
f.HtmlOptions.ImageSubFolder = String.Format("{0}_images", Path.GetFileNameWithoutExtension(pdfFile))
f.HtmlOptions.ImageFileName = "picture"
f.EmbeddedImagesFormat = PdfFocus.eImageFormat.Auto
f.HtmlOptions.IncludeImageInHtml = False
Dim htmlFile As String = Path.GetFileNameWithoutExtension(pdfFile) & ".html"
Dim htmlFilePath As String = Path.Combine(htmlDirectory.FullName, htmlFile)
If f.ToHtml(htmlFilePath) = 0 Then
success += 1
End If
End If
Next pdfFile
Console.WriteLine("{0} of {1} files converted successfully!", success, total)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(htmlDirectory.FullName) With {.UseShellExecute = True})
End Sub
Private Shared Sub ConvertMultiplePdfToSingleHtml()
Dim pdfDirectory As String = Path.GetFullPath("..\")
Dim htmlFile As String = "Result.html"
Dim pdfFiles() As String = Directory.GetFiles(pdfDirectory, "*.pdf")
Dim singleHtml As New StringBuilder()
singleHtml.Append("<html>" & vbCrLf & "<head>" & vbCrLf)
singleHtml.Append("<meta http-equiv = ""Content-Type"" content=""text/html; charset=utf-8"" />")
singleHtml.Append(vbCrLf & "</head>" & vbCrLf & "<body>")
Dim f As New PdfFocus()
Dim success As Integer = 0
Dim total As Integer = 0
For Each pdfFile As String In pdfFiles
Console.WriteLine("Converting {0} ...", Path.GetFileName(pdfFile))
f.OpenPdf(pdfFile)
total += 1
If f.PageCount > 0 Then
f.HtmlOptions.IncludeImageInHtml = False
f.HtmlOptions.ImageSubFolder = String.Format("{0}_images", Path.GetFileNameWithoutExtension(pdfFile))
f.HtmlOptions.ImageFileName = "picture"
f.EmbeddedImagesFormat = PdfFocus.eImageFormat.Auto
f.HtmlOptions.InlineCSS = True
f.HtmlOptions.ProduceOnlyHtmlBody = True
Dim tempHtml As String = f.ToHtml()
If Not String.IsNullOrEmpty(tempHtml) Then
success += 1
singleHtml.Append(tempHtml)
End If
End If
Next pdfFile
singleHtml.Append("</body></html>")
File.WriteAllText(htmlFile, singleHtml.ToString())
Console.WriteLine("{0} of {1} files converted and merged into {2}!", success, total, Path.GetFileName(htmlFile))
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(htmlFile) With {.UseShellExecute = True})
End Sub
End Class
End Namespace
See Also