Convert from .html to .pdf

I downloaded a .html file by save as html from chrome.
The web site where I downloaded is the google home page.

I used below funtion to convert this .html file to .pdf. But I can only insert one resource file.
I want to know how can I insert all of the resource files?

second question, I saved a .html file by save as html from ie, when I used the .html file, I got an exception.Why?

Does this function support my case?I really need your help, thanks for any reply!

public static void PDFNEWNET_34393() { string inHtml = @"D:/Downloads/google.html"; string outPdf = @"D:/Downloads/google.pdf";

        HtmlLoadOptions options = new HtmlLoadOptions();
        options.CustomLoaderOfExternalResources = new LoadOptions.ResourceLoadingStrategy(SamePictureLoader);
        Document pdfDocument = new Document(inHtml, options);
        pdfDocument.Save(outPdf);
    }

private static LoadOptions.ResourceLoadingResult SamePictureLoader(string resourceURI)
{

        byte[] resultBytes = File.ReadAllBytes(@"D:/Downloads/google/chrome-48.png");
        LoadOptions.ResourceLoadingResult result = new LoadOptions.ResourceLoadingResult(resultBytes);
        
        return result;
    }
Hi Leo,

Thanks for your inquiry.

leo.li415:
I downloaded a .html file by save as html from chrome. The web site where I downloaded is the google home page.

I used below funtion to convert this .html file to .pdf. But I can only insert one resource file.
I want to know how can I insert all of the resource files?


I am afraid currently HtmlLoadOptions support a single basepath setting. However, I have logged an enhancement ticket PDFNEWNET-39247 for further investigation and rectification. We will notify you as soon as it is resolved.

leo.li415:
I downloaded a .html file by save as html from chrome. The web site where I downloaded is the google home page. I used below funtion to convert this .html file to .pdf. But I can only insert one resource file. I want to know how can I insert all of the resource files? second question, I saved a .html file by save as html from ie, when I used the .html file, I got an exception.Why? Does this function support my case?I really need your help, thanks for any reply!

public static void PDFNEWNET_34393() { string inHtml = @“D:/Downloads/google.html”; string outPdf = @“D:/Downloads/google.pdf”; HtmlLoadOptions options = new HtmlLoadOptions(); options.CustomLoaderOfExternalResources = new LoadOptions.ResourceLoadingStrategy(SamePictureLoader); Document pdfDocument = new Document(inHtml, options); pdfDocument.Save(outPdf); } private static LoadOptions.ResourceLoadingResult SamePictureLoader(string resourceURI) { byte[] resultBytes = File.ReadAllBytes(@“D:/Downloads/google/chrome-48.png”); LoadOptions.ResourceLoadingResult result = new LoadOptions.ResourceLoadingResult(resultBytes); return result; }


Please note CustomLoaderOfExternalResources works only when we set explicitly UseNewConversionEngine to true. So you are getting the exception. Moreover, this property is used then you need to apply some specific logic in case of a resource. E.g replacing images with a specific image or restricting some specific resource paths etc. As per my understanding you do not need to use this in your case.

Best Regards,