Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed May 22, 2019 9:55 am

Hello,

i'm trying to add an image in html code with the NewPlugin htmlconverter.

I tried from folder in disk:

Code: Select all
        <div class="divLogo">
            <img src="C:\Images\logo.jpg" />
        </div>


and from folder in solution

Code: Select all
       
 <div class="divLogo">
            <img src="Images\logo.jpg" />
</div>


but image doesn't appear in pdf document.

Can you help me with this?

Regards

abcdata
 
Posts: 5
Joined: Thu Oct 18, 2018 10:59 am

Thu May 23, 2019 7:37 am

Hi,

Thanks for you inquiry.
Kindly note that when using Plugin method to convert html to Pdf, our Spire.Pdf supports parsing absolute path in this way: <img src="file:///C:/Image/logo.jpg" />, but doesn't support parsing <img src="C:\Images\logo.jpg" />, thus, please add the file:/// into absolute paths to import your pictures.
And I also tested the relative path <img src="Images\logo.jpg" /> in my html file, but didn't encounter any issue. If you were using an old version, I would suggest that you try the latest Spire.PDF Pack(Hot Fix) Version:5.5.1. If the issue still occurs after trying, Please provide your full code to help us further look into your issue. You could send them to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Thu May 23, 2019 8:22 am

Thank you, your solution works great but if i want use a relative path to file in folder in my webapplication image doesn't appear? ex. Images\logos\logo.jpg

I use Spire.pdf ver. 5.5.10.18046

Application runs on IISExpress

abcdata
 
Posts: 5
Joined: Thu Oct 18, 2018 10:59 am

Thu May 23, 2019 11:00 am

Hi,

Thanks for your feedback.
You were converting the html code to Pdf directly, right? I did notice that the image with relative path didn't appear after converting the html code to Pdf. Sorry for the inconvenience caused. However, you could put your html code in a html file, and then convert the html file to Pdf. I have confirmed this way has no problem. The premise is that the path of your image folder is correct, that is to say, if you open your html directly in browser, the image could be rendered successfully. Attached my testing code for your reference. If there is any question or misunderstanding, please feel free to write back.
Code: Select all
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(Server.MapPath("sample.html"), "C:\\result.pdf",

    //enable javascript
    true,

    //load timeout
    100 * 1000,

    //page size
    PdfPageSize.A4,

    //page margins
    new PdfMargins(0, 0));

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed May 29, 2019 9:26 am

Hi,

How is your issue now?
Thanks in advance for your valuable feedback and time.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Sat Jun 25, 2022 9:58 pm

I am also facing the same issue, Image is not showing in PDF.

version : spire.office.free 5.3.1 in java

<div class="logo-area">
<img src="file:///D:/image/pdf-logo.png"/>
<p>201 1st St SE</p>
</div>

sanyasiraju
 
Posts: 2
Joined: Sat Jun 25, 2022 7:18 pm

Mon Jun 27, 2022 9:46 am

Hi,

I did an initial test and noticed that converting html code to PDF can reproduce your problem, but putting code in an HTML file for conversion worked fine. I posted the problem to our bug tracking system with the problem number SPIREPDF-5295. I will let you know as soon as the problem is resolved or there is any update. Sorry for the inconvenience.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Tue Jun 28, 2022 1:32 pm

Thanks a lot,

Can you please let me know, how to pass file instead of string using spring.pdf free.

As of I am doing the conversion using below,

HtmlConverter.convert(message.getHtml(), outputFile, true, 300000, new Size(595 , 842), new PdfMargins(0), LoadHtmlType.Source_Code);


Regards,
Raju

sanyasiraju
 
Posts: 2
Joined: Sat Jun 25, 2022 7:18 pm

Wed Jun 29, 2022 3:00 am

Hi,

Thank you for your reply.
Please refer to the code below to achieve your requirement. If you have any questions, please feel free to contact us.
Code: Select all
                HtmlConverter.convert(
                //Load .html file
                "D:\\image\\pdf_log.html",
                //Output document
                "HtmlToPdf.pdf",
                //Enable javascript
                true,
                //Load timeout
                1000000000,
                //Page size
                new Size((float) PdfPageSize.A4.getWidth(), (float)PdfPageSize.A4.getHeight()),
                //Page margins
                new PdfMargins(30,50), LoadHtmlType.URL);

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF