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.

Mon Jan 04, 2021 5:31 am

I'm using spire.office to convert html to pdf in my .net core web application. It's working fine in local, but when I deploy the project in Azure. It's not working. When I try to convert a html string to stream using new HtmlConverter plugin and try to write into a pdf. Pdf is not generated successfully and its size is 0kb. can you please tell me what is going wrong!.

Here is my code:

using (MemoryStream pdfstream = new MemoryStream())
{
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(htmltext,
pdfstream,
true,
10 * 1000,
new SizeF(PdfPageSize.A4),
new Spire.Pdf.Graphics.PdfMargins(sourceFile.MarginLeft, sourceFile.MarginTop, sourceFile.MarginRight, sourceFile.MarginButtom),
LoadHtmlType.SourceCode
);
byte[] pdfarray = pdfstream.ToArray();
File.WriteAllBytes(filename, pdfarray);
}

I have tried this too:

Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(ImgHtml,
filename,
true,
10 * 1000,
new SizeF(PdfPageSize.A4),
new Spire.Pdf.Graphics.PdfMargins(sourceFile.MarginLeft, sourceFile.MarginTop, sourceFile.MarginRight, sourceFile.MarginButtom),
LoadHtmlType.SourceCode
);
PDFs.Add(filename);

It's not generating any file.

Please help me into this.

abhik.abhi
 
Posts: 3
Joined: Fri Jan 01, 2021 12:12 pm

Mon Jan 04, 2021 6:46 am

Hello,

Thanks for your inquiry.
I simulated a Html string and did an initial test, but didn't reproduce your issue. To help us investigate your issue more accurately, please help to share us with your input html file for reference. Thanks in advance.

Sincerely,
Sofia
E-iceblue support team
User avatar

Sofia.Yang
 
Posts: 84
Joined: Tue Jul 14, 2020 1:41 am

Mon Jan 04, 2021 10:38 am

I have tested using a simple html text.

string htmltext = "<!DOCTYPE html><html><head><title>Page Title</title><style>.class1{color: red;}.class2{color: blue;}</style></head><body><h1 class='class1'>My First Heading</h1><p class='class2'>My first paragraph.</p></body></html>";

I'm using Spire.Office 5.12.0 without license.

abhik.abhi
 
Posts: 3
Joined: Fri Jan 01, 2021 12:12 pm

Tue Jan 05, 2021 8:06 am

Hello,

Thank you for sharing more information.
After testing your Html string with our latest version(Spire.Office Platinum(Hotfix) Version:5.12.8), it also works on local and Azure. Here I uploaded my testing demo which I used Windows X64 plugin. The screenshots folder contains some setting screenshots. Please check and run it on your side. If there is still any issue, just feel free to write back.

Sincerely,
Sofia
E-iceblue support team
User avatar

Sofia.Yang
 
Posts: 84
Joined: Tue Jul 14, 2020 1:41 am

Thu May 18, 2023 8:52 am

I am having the same issue as below
[quote="abhik.abhi"]I'm using spire.office to convert html to pdf in my .net core web application. It's working fine in local, but when I deploy the project in Azure. It's not working. When I try to convert a html string to stream using new HtmlConverter plugin and try to write into a pdf. Pdf is not generated successfully and its size is 0kb. can you please tell me what is going wrong!.

Here is my code:


MemoryStream pdfstream = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html,
pdfstream,
true,
10 * 1000,
new SizeF(PdfPageSize.A4),
new Spire.Pdf.Graphics.PdfMargins(0),
LoadHtmlType.SourceCode
);

I am using free spire.pdf and application is deployed in azure.

I tried by installing Spire.Office Platinum but same issue exists.

I have testing with html text still issue exists.

Please help on this
Last edited by bhavani_m007 on Thu May 18, 2023 10:21 am, edited 1 time in total.

bhavani_m007
 
Posts: 4
Joined: Wed Apr 19, 2023 9:47 am

Thu May 18, 2023 9:43 am

bhavani_m007 wrote:MemoryStream pdfstream = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html,
pdfstream,
true,
10 * 1000,
new SizeF(PdfPageSize.A4),
new Spire.Pdf.Graphics.PdfMargins(0),
LoadHtmlType.SourceCode
);

I am using free spire.pdf nas application is deployed in azure.

The pdf stored in azure portal but the pdf not generated properly when iam using thr above mnetion code

I tried by installing Spire.Office Platinum but same issue exists.

I have testing with html text still issue exists.

When I ran though local pdf generated but when i deployed the application in azure pdf not generated.

Hi,

Thanks for your feedback.
To help us reproduce your issue and work out a solution for you, could you please share us with your test html? You can send it to us via email (support@e-iceblue.com) or attach it here. Thanks for your assistance.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu May 18, 2023 10:26 am

Triste.Dai wrote:
bhavani_m007 wrote:MemoryStream pdfstream = new MemoryStream();
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html,
pdfstream,
true,
10 * 1000,
new SizeF(PdfPageSize.A4),
new Spire.Pdf.Graphics.PdfMargins(0),
LoadHtmlType.SourceCode
);

I am using free spire.pdf nas application is deployed in azure.

The pdf stored in azure portal but the pdf not generated properly when iam using thr above mnetion code

I tried by installing Spire.Office Platinum but same issue exists.

I have testing with html text still issue exists.

When I ran though local pdf generated but when i deployed the application in azure pdf not generated.

Hi,

Thanks for your feedback.
To help us reproduce your issue and work out a solution for you, could you please share us with your test html? You can send it to us via email (support@e-iceblue.com) or attach it here. Thanks for your assistance.

Best regards,
Triste
E-iceblue support team




Hi, Thank you for the repsonse, Below is my html content

Code: Select all
<br/>
<div style="width:300px; align-self:center">
    <p class="MsoNormal" style="text-align:center">
        &nbsp;Aeroship Handling Ltd
            <br />
            9300 Airport Rd
                ,9300 Airport Rd
                    <br />
                    Ontario
                        ,Mount Hope
                             L0R 1W0
                                <br />
                                +1-905-679-6888


    </p>
    <p class="MsoNormal">
        &nbsp;
    </p>
    <p class="MsoNormal" style="text-align:center">
        AIRCRAFT SERVICE RECORD
    </p>
    <p class="MsoNormal">
        &nbsp;
    </p>
    <p class="MsoNormal">
        <span style="width: 50%;float: left; text-align: left;">DATE & TIME&nbsp; </span><span style="width: 50%;float: left; text-align:Right;">&nbsp;2023-04-17 08:42</span>
    </p>
    <p class="MsoNormal">
        <span style="width: 50%;float: left; text-align: left;">AIRPORT&nbsp; </span><span style="width: 50%;float: left; text-align:Right;">&nbsp;YHM</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >TICKET NUMBER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;711</span>
    </p><p class="MsoNormal">
       <span  style="width: 50%;float: left; text-align: left;" >AIRLINE&nbsp; </span>
    </p>      <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align:Right;" >&nbsp;Swoop</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >FLIGHT NUMBER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;WO602</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >AIRCRAFT TYPE&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;7S8</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >TAIL NUMBER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;CGXRW</span>
    </p>
    <p class="MsoNormal">
        &nbsp;
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >ORIGIN&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;YHM</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >DESTINATION&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;PVR</span>
    </p>
    <p class="MsoNormal">
        &nbsp;
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >TRANSACTION&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;Fuel</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >FUEL TYPE&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;Jet A1</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >TRUCK NUMBER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >FUELING LOCATION&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;10</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >FUELER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;Airport Admin</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >ON ROAD&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;NO</span>
    </p>
     
    <p class="MsoNormal" style="text-align:center;border-bottom: 1px;border-bottom-style: dashed;">
        &nbsp;
    </p>
   
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >START&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;2023-04-17 08:40</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >FINISH&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;2023-04-17 08:42</span>
    </p>
   
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >SYS.NET TOTAL BEGIN L&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;0.00 ltrs</span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >SYS.NET TOTALIZER&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;0.00 ltrs</span>
    </p>
    <p class="MsoNormal" style="text-align:center;">
        <span>=====&nbsp;DELIVERY&nbsp;=====</span>
    </p>
     <p class="MsoNormal" style="font-size:18px">
        <span  style="width: 50%;float: left; text-align: left;" >GROSS DELIVERED&nbsp;L </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;852 ltrs</span>
    </p>
     <p class="MsoNormal" style="font-size:18px">
        <span  style="width: 50%;float: left; text-align: left;" >Average Temparature &nbspC; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;852 ltrs</span>
    </p>
    <p class="MsoNormal" style="font-size:18px">
        <span  style="width: 50%;float: left; text-align: left;" >TOTAL DELIVERED&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;852 ltrs</span>
    </p> 
     <p class="MsoNormal" style="font-size:18px">
        <span  style="width: 50%;float: left; text-align: left;" >TABLE&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;852 ltrs</span>
    </p>
    <p class="MsoNormal" style="text-align:center">
        <span  style="width: 50%;float: left; text-align: left;" > &nbsp; </span><span  style="width: 50%;float: left; text-align:Right;" >&nbsp;&nbsp; </span>
    </p>
    <p class="MsoNormal">
        <span  style="width: 50%;float: left; text-align: left;" >RECIEVED BY&nbsp; </span><span  style="width: 50%;float: left; text-align:Right;border-bottom: 1px;border-bottom-style: dashed;">&nbsp; </span>
    </p>

    <p class="MsoNormal" style="text-align:center">
        &nbsp;
    </p>
    <p class="MsoNormal" style="text-align:center;height:200px">
        <img src='https://jetonefilesdev.blob.core.windows.net/fuelticketqrcode/711.bmp' style='height:200px; width:200px' />
    </p>
</div>
<style type="text/css">
    p.MsoNormal, li.MsoNormal, div.MsoNormal {
        margin-top: 0cm;
        margin-right: 0cm;
        margin-bottom: 3.0pt;
        margin-left: 0cm;
        line-height: 100%;
        font-size: 11.0pt;
        font-family: "Calibri", "sans-serif";
    }

    p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing {
        margin: 0cm;
        margin-bottom: .0001pt;
        font-size: 11.0pt;
        font-family: "Calibri", "sans-serif";
    }

    .MsoPapDefault {
        margin-bottom: 10.0pt;
        line-height: 115%;
    }

    .DivLeft, .DivRight {
        width: 50%;
        float: left;
    }

    .DivLeft {
        text-align: left;
    }

    .DivRight {
        text-align: right;
    }

    @page Section1 {
        size: 595.3pt 841.9pt;
        margin: 72.0pt 72.0pt 72.0pt 72.0pt;
    }

    div.Section1 {
        page: Section1;
    }
</style>

bhavani_m007
 
Posts: 4
Joined: Wed Apr 19, 2023 9:47 am

Fri May 19, 2023 8:30 am

Hi,

Thanks for your feedback.
I created a simple ASP.NET Core Web App based on .NET6 and deployed it to Azure, using the latest Spire.PDF, your html string was able to be converted correctly, I have attached the output document for your reference. Could you please share us with more information?
1) Did you set the Application platform in Azure settings? (See the screenshots below).
platform.png

2) The version of the qt plugin you are using.
3) The OS of your Azure instance.
4) Your test project (if available).

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon May 22, 2023 8:59 am

Hi,

1) Did you set the Application platform in Azure settings? (See the screenshots below).
Yes.
2)The version of the qt plugin you are using.
5.14.20
3) The OS of your Azure instance.
Windows

4) Your test project (if available).
sample code provided below
Code: Select all
MemoryStream pdfstream = new MemoryStream();
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html,
            pdfstream,
            true,
            10 * 1000,
            new SizeF(PdfPageSize.A4),
            new Spire.Pdf.Graphics.PdfMargins(0),
            LoadHtmlType.SourceCode
            );



When I am running local also pdf file not generated and we are getting below error

ReadTimeout = 'pdfstream.ReadTimeout' threw an exception of type 'System.InvalidOperationException'

Please help us to resolve this issue as early as possible.

bhavani_m007
 
Posts: 4
Joined: Wed Apr 19, 2023 9:47 am

Tue May 23, 2023 5:52 am

Hi,

Thanks for your feedback.
I created an ASP. Net Web App based on the. NET 4.8 in your screenshot. Using the latest Spire.PDF and the QT plugin (version 5.9.8 and 5.14.2),in some cases, there seems to be a slight issue with version 5.14.2 on Azure, I have tested both locally and on Azure, and version 5.9.8 is working properly, I have attached the download link of the plugin, please download and have a test.
If you have any further questions or concerns, just feel free to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Tue May 23, 2023 6:25 am

Hi,

Thank you for the response,

We have added 5.9.8.0 version dlls but issue not resolved.
Below id my code
Code: Select all

MemoryStream pdfstream = new MemoryStream();
            Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(html,
            pdfstream,
            true,
            10 * 1000,
            new SizeF(PdfPageSize.A4),
            new Spire.Pdf.Graphics.PdfMargins(0),
            LoadHtmlType.SourceCode
            );

pdfstream.Position = 0;

                var storageAccount = CloudStorageAccount.Parse(connectionstoragestring);

                var blobClient = storageAccount.CreateCloudBlobClient();

                var cloudBlobContainer = blobClient.GetContainerReference(containernmae);

                // Get Blob reference

                var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(filename+".pdf");

                // Write to blob
                await cloudBlockBlob.UploadFromStreamAsync(pdfstream);

                string fileUrl = cloudBlockBlob.Uri.AbsoluteUri;


I have tested local but generated pdf with 0 kb, attached the screenshot

bhavani_m007
 
Posts: 4
Joined: Wed Apr 19, 2023 9:47 am

Tue May 23, 2023 8:01 am

Hi,

Thanks for your feedback.
I have attached my test project for your reference. You can download it from this link and have a test, please change the plugin path in HomeController manually, then run the project. There may be some difference between our code, you can make some adjustments.

If you have any further questions or concerns, just feel free to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Tue Nov 12, 2024 10:31 pm

I am having same issue, using Spire.PDF version 10.11.1 trial version to generate HTML to pdf. Using below code in ASP .NET 4.8 Web API, with QTPlugin (64 bit). Ensured all QTPlugin path are ok. The code works in local but when deployed to Azure AppService it does not work. It generates a BLANK stream or zero length stream. The project is compiled as 64 bit too, still nothing works. we have Spre .PDF 8.0 license and were plannig to upgrade, but this is not working. Quick help will be appreciated , HOW TO FIX THIS ISSUE ? PLEASE PROVIDE CODE THAT CAN WORK WITH VERSION THAT CAN MAKE IT WORK ?


string base64Response = string.Empty;
string intLen;
string html = "<h1>THIS IS TEST PDF</h1>";
string pluginPath = $@"{AppDomain.CurrentDomain.BaseDirectory}QTPlugins";
string filePath = $@"{AppDomain.CurrentDomain.BaseDirectory}test.pdf";

using (MemoryStream memoryStream = new MemoryStream())
{
try
{

// Set the plugin path for Spire.PDF
HtmlConverter.PluginPath = pluginPath ;

// Define page settings
PdfPageSettings pageSettings = new PdfPageSettings
{
Size = PdfPageSize.A4,
Margins = new PdfMargins(20, 20, 20, 20)
};

// Convert HTML to PDF and write to memoryStream
HtmlConverter.Convert(html, memoryStream, false, 300, pageSettings.Size, pageSettings.Margins, LoadHtmlType.SourceCode);
HtmlConverter.Convert(html, filePath, false, 300, pageSettings.Size, pageSettings.Margins, LoadHtmlType.SourceCode);

// Convert MemoryStream to Base64
byte[] pdfBytes = memoryStream.ToArray();
intLen = pdfBytes.Length.ToString();
logger.LogInfo($"Byte array Length : [{intLen}]");
base64Response = Convert.ToBase64String(pdfBytes);
}
catch (Exception ex)
{
logger.LogInfo($"Error : [{ex.ToString()}]");

// Log the exception (replace with your logging framework)
throw ex;
}
}

vikyjain80
 
Posts: 2
Joined: Tue Nov 12, 2024 5:29 pm

Wed Nov 13, 2024 8:11 am

Hi,

Thank for your message.
Could you please tell us what system (e.g., Windows) you used for testing on Azure, so that we can further investigate?

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 409
Joined: Mon Nov 07, 2022 8:10 am

Wed Nov 13, 2024 10:03 pm

We are using Azure Windows AppService environment with ASp .NET 4.8. The code is in ASP .NET 4.8 API. One more problem we faced is that when we deploy this to Azure and Spire.PDF is called then it uses some exe internally and that gets locked. Ther esult is we are not able to deploy further code as this get locked in AppService and after that we have to restart the AppService to unlock this. The exe should get released after its done.

vikyjain80
 
Posts: 2
Joined: Tue Nov 12, 2024 5:29 pm

Return to Spire.PDF