Hi there
I’m using Aspose PDF for .net 18.12.
i try to convert html to pdf but i get only exception (illegal characters in the path).
below is my code.
// first try
string src = “d:\html.html”;
string dst = “d:\html.html.pdf”;
try
{
FileStream fs = new FileStream(src, FileMode.Open, FileAccess.Read);
MemoryStream stream = new MemoryStream();
fs.CopyTo(stream);
HtmlLoadOptions options = new HtmlLoadOptions(Path.GetDirectoryName(src));
Document pdfDocument = new Document(stream, options); // !!!!! exception here !!!!!
pdfDocument.Save(dst);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// second try
string src = “d:\html.html”;
string dst = “d:\html.html.pdf”;
try
{
HtmlLoadOptions options = new HtmlLoadOptions(Path.GetDirectoryName(src));
Document pdfDocument = new Document(src, options); // !!! exception here !!!
pdfDocument.Save(dst);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// third try
string dst = “d:\html.html.pdf”;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
// Create a request for the URL.
WebRequest request = WebRequest.Create(“https://En.wikipedia.org/wiki/Main_Page”);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Time out in miliseconds before the request times out
// Request.Timeout = 100;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions(“https://En.wikipedia.org/wiki/”);
// Load HTML file
Document pdfDocument = new Document(stream, options); // !!! exception here !!!
options.PageInfo.IsLandscape = true;
// Save output as PDF format
pdfDocument.Save(dst);