A bad href link in html for example “http://415.707.7015/” throws a failed to parse exception that does not allow for processing to continue. Work arounds here suggest pre-validating all hrefs in the entire html before attempting to use Aspose to convert. This seems like a very clunky requirement for users of your SDK. The better solution would be for Aspose add an option to ignore bad href links. Another simple option would be to continue processing and create the pdf but also call the load warning handler that could be used to decide whether or not the user of the SDK wants to use the generated pdf after it is created. This to me seems like a bug or design flaw in the library.
Summary
When Aspose.PDF for .NET loads an HTML file that contains a malformed hyperlink (for example ), the HTML parser validates the href` value, throws “Failed to parse URL for bad links”, and aborts the conversion to PDF.
Why it happens
During the HTML‑to‑PDF conversion the library treats every href as a required part of the document structure. If a URL cannot be parsed, the default behaviour is to raise an exception rather than continue, which stops the PDF generation.
What to do next
- Disable strict URL validation while loading the HTML
using System.IO;
using System.Text;
using Aspose.Pdf;
using Aspose.Pdf.LoadOptions;
Read the HTML source (file, string, stream, etc.)
string html = File.ReadAllText("input.html", Encoding.UTF8);
HtmlLoadOptions – set ValidateExternalLinks to false
HtmlLoadOptions loadOptions = new HtmlLoadOptions
{
When false, malformed href attributes are ignored and the conversion continues.
ValidateExternalLinks = false
};
Load the HTML and convert to PDF
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
Document pdfDoc = new Document(ms, loadOptions);
pdfDoc.Save("output.pdf");
}
HtmlLoadOptions.ValidateExternalLinks = false tells Aspose.PDF to skip URL parsing errors, allowing the rest of the document to be processed.
- Optionally capture warnings about ignored links
Aspose.PDF provides a warning‑handling mechanism. Implement IWarningHandler (or use the built‑in WarningHandler) to log any URLs that were skipped:
using Aspose.Pdf;
using Aspose.Pdf.Exceptions;
class LinkWarningHandler : IWarningHandler
{
public void HandleWarning(WarningInfo info)
{
Example: log only URL‑related warnings
if (info.WarningType == WarningType.InvalidUrl)
Console.WriteLine($"Ignored bad link: {info.Message}");
}
}
After creating the Document:
pdfDoc.WarningHandler = new LinkWarningHandler();
This step is optional; the conversion will succeed even without it.
- If the property is unavailable in your version
Upgrade – ValidateExternalLinks was introduced in recent releases (24.x series and later). Updating to a newer Aspose.PDF for .NET version will give you access to this option.
- Fallback when you cannot upgrade
- Pre‑process the HTML to remove or replace malformed URLs (e.g., replace them with
#or an empty string) before callingnew Document(...). - Wrap the load call in a
try / catch. If an exception is caught, clean the HTML and retry the conversion.
By turning off strict link validation (or by cleaning the HTML beforehand), the conversion proceeds without being halted by bad hyperlinks, while the optional warning handler lets you keep track of any problematic links that were ignored.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
I’m using that latest version of Aspose.Pdf.Drawing, version 25.10. I’m using this version so that I can run on Linux. The option ValidateExternalLinks is not an available option for Aspose.Pdf.HtmlLoadOptions. Also I have a warning handler in place and it does not call it for any bad ref links, there is no warning type WarningType.InvalidUrl.
We apologize for the confusion. The above reply was generated and posted by the AI and it can make mistakes. We are constantly working on improving the quality.
Nevertheless, we have observed your comments and will definitely investigate this scenario in details. Would you please share a sample HTML in .zip format and the minimal code snippet for our reference? We will log an investigation ticket in our issue management system and share the ID with you.
Would you please share the sample code snippet as well - as requested earlier? We will use the same code sample to replicate the issue and address it accordingly.