Convert Web page URL to PDF using Aspose.HTML REST API returns 200 with empty content

I’m evaluating Aspose.Html. I can successfully convert some web pages, but when I try the following URL, GetConvertDocumentToPdfByUrl returns a status of 200 but no content. When I try the same URL in the online converter (HTML to PDF Converter - free online app | Convert HTML from anywhere) it fails with ‘Conversion Faulted’

https://reporting-delivery-service.azurewebsites.net/report

Any idea what’s causing the failure?

I know the content is badly formatted - it’s just a test document.

@dave.chamberlain

We have noticed the reported issue while converting your shared URL. So logged a ticket HTMLCLOUD-1749 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

@tial.ahmad
Thanks for that.
I’m doing an evaluation. We would like to use Aspose.Html if we can as we are using other Aspose products, but I’m having some problems. Is it possible to email someone with these questions?

Summary of questions:

I’ve set up a trial account and associated 2 ‘storages’. One is an Azure storage account, and the other is Internal. When I use the storage API:
storageApi.StorageExists(“davetest”);
This always returns false. I don’t understand why.

When I call this method:
convApi.PostConvertDocumentToPdf(_htmlFileName, “dave.pdf”, width, height, leftMargin, rightMargin, topMargin, bottomMargin);
It fails with a 500. Using fiddler, the error message seem to be:
AmazonS3 Storage exception: The specified key does not exist. Bucket ‘afc-filestorage’, FilePath ‘79719/14d74dc9-6d64-4689-aa10-432880ffd8f4/HTMLPage1.html’
This is strange as I didn’t set up Amazon storage. I only set up Azure storage and Internal storage. I can’t get this method to work.

When I look at the API Usage Log for the above request, it seems to indicate that the status code was 400 with this error:
Error: GetConvertDocumentToPdf. Error result: Dynabic.ProductsRestApi.Common.Error.ApiError
Also the URL looks wrong (the ? is missing after pdf):
GET http://api.aspose.cloud/v3.0/html/HTMLPage1.html/convert/pdfwidth=800&height=1200&leftMargin=15&rightMargin=15&topMargin=15&bottomMargin=15

@dave.chamberlain

Thanks for your inquires.

Please verify that your both storages are listed there and you can view the files in these storages.

@dave.chamberlain

We have hosted our storage on AmazonS3 so you are getting the exception from AmazonS3. Please share your sample code here in this post and also share your credentials(ClientId/Secret) via a private message. We will investigate the issue and will guide you accordingly.

When I use the dashboard I can see both storages, and both contain a single file. When I use the API, StorageExists returns false for both storages.

We have hosted our storage on AmazonS3 so you are getting the exception from AmazonS3.

I get this error even though my Azure storage account is set to be the default.

Here’s the code (C#):

    static void AsposeTest()
    {
        var CLIENT_ID = "<redacted>";
        var CLIENT_SECRET = "<redacted>";
        var BASEPATH = "https://api.aspose.cloud";
        var AUTHPATH = "https://api.aspose.cloud";

        IStorageApi storageApi = new StorageApi(CLIENT_ID, CLIENT_SECRET, BASEPATH, AUTHPATH);
        var x = storageApi.StorageExists("davetest");
        var y = storageApi.StorageExists("cubiksdavetest");

        Console.WriteLine($"davetest exists: {x}. cubiksdavetest exists: {y}");

        var sourceUrl = "https://reporting-delivery-service.azurewebsites.net/report";
        var width = 800;
        var height = 1200;
        var leftMargin = 15;
        var rightMargin = 15;
        var topMargin = 15;
        var bottomMargin = 15;
        var fileName = "HTMLPage1.html";
        var outPath = @"c:\temp";

        IConversionApi convApi = new HtmlApi(CLIENT_ID, CLIENT_SECRET, BASEPATH, AUTHPATH);
        try
        {
            var response = convApi.GetConvertDocumentToPdfByUrl(
                sourceUrl, width, height,
                leftMargin, rightMargin, topMargin, bottomMargin);

            if (response?.ContentStream != null)
            {
                var stream = response.ContentStream;
                var outFile = Path.Combine(outPath, response.FileName);

                if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);

                using var fstr = new FileStream(outFile, FileMode.Create, FileAccess.Write);
                stream.CopyTo(fstr);
                fstr.Flush();

                Console.WriteLine($"GetConvertDocumentToPdfByUrl Succeeded ({response.Status}): result file saved to {outFile}");
            }
            else
            {
                Console.WriteLine("Empty response");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine($"Exception from GetConvertDocumentToPdfByUrl: {e}");
            throw;
        }

        try
        {
            var response = convApi.GetConvertDocumentToPdf(
                fileName, width, height,
                leftMargin, rightMargin, topMargin, bottomMargin,
                null, null);

            if (response?.ContentStream != null)
            {
                var stream = response.ContentStream;
                var outFile = Path.Combine(outPath, response.FileName);

                if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);

                using var fstr = new FileStream(outFile, FileMode.Create, FileAccess.Write);
                stream.CopyTo(fstr);
                fstr.Flush();

                Console.WriteLine($"GetConvertDocumentToPdf Succeeded: result file saved to {outFile}");
            }
            else
            {
                Console.WriteLine("Empty response");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine($"Exception from GetConvertDocumentToPdf: {e}");
        }

        try
        {
            var response = convApi.PostConvertDocumentToPdf(fileName, $"report.pdf", width, height, leftMargin, rightMargin, topMargin, bottomMargin, null);
            if (response != null)
            {
                Console.WriteLine($"PostConvertDocumentToPdf Succeeded ({response.Status}): Result file uploaded as report.pdf");
            }
        }
        catch (Exception e)
        {
            Console.WriteLine($"Exception from PostConvertDocumentToPdf: {e}");
        }
    }

The output of this code is:

davetest exists: False. cubiksdavetest exists: False
GetConvertDocumentToPdfByUrl Succeeded (OK): result file saved to c:\temp\report_converted.pdf
Exception from GetConvertDocumentToPdf: Aspose.Html.Cloud.Sdk.Client.ApiException: Error calling GetConvertDocumentToPdf: StatusCode=500 (InternalServerError); Internal Server Error
   at Aspose.Html.Cloud.Sdk.Api.Internal.ApiImplBase.CallGetApi(String path, Dictionary`2 queryParams, String methodName) in C:\Source\Samples\aspose-html-cloud-dotnet\Aspose.HTML-Cloud\Api\Internal\ApiImplBase.cs:line 69
   at Aspose.Html.Cloud.Sdk.Api.Internal.ConversionApiImpl.GetConvertDocumentToPdf(String name, Nullable`1 width, Nullable`1 height, Nullable`1 leftMargin, Nullable`1 rightMargin, Nullable`1 topMargin, Nullable`1 bottomMargin, String folder, String storage) in C:\Source\Samples\aspose-html-cloud-dotnet\Aspose.HTML-Cloud\Api\Internal\ConversionApiImpl.cs:line 174
   at Aspose.Html.Cloud.Sdk.Api.HtmlApi.GetConvertDocumentToPdf(String name, Nullable`1 width, Nullable`1 height, Nullable`1 leftMargin, Nullable`1 rightMargin, Nullable`1 topMargin, Nullable`1 bottomMargin, String folder, String storage) in C:\Source\Samples\aspose-html-cloud-dotnet\Aspose.HTML-Cloud\Api\HtmlApi.cs:line 413
   at HtmlToPdfTest.Program.AsposeTest() in C:\Source\NexusReporting\HtmlToPdfTest\Program.cs:line 179
PostConvertDocumentToPdf Succeeded (NoContent): Result file uploaded as report.pdf

The PDF output from GetConvertDocumentToPdfByUrl is a 0 length file.

@dave.chamberlain

We are sorry for the inconvenience. We have reproduced the reported issues and logged the following tickets in our issue tracking system for rectification. We will notify you as soon as these are resolved.

HTMLCLOUD-1750: GetConvertDocumentToPdf API returns 500 internal error
HTMLCLOUD-1751: StorageExists API issue

Hi Tilal,

Thanks for the feedback.

Is this a bug? Do you have any timeframe for fixing it? I’m only going to be evaluating HTML to PDF converters for a short time. Is there any workaround I can try?

@dave.chamberlain

Yes, it seems bug. I am afraid we cannot share any timeline at the moment as these tickets are pending for further investigation.

As a workaround, you can use the following API methods of Aspose.PDF Cloud.

​GET /pdf​/create​/web Convert web page to PDF format and return resulting file in response

PUT ​/pdf​/{name}​/create​/web Convert web page to PDF format and upload resulting file to storage

GET ​/pdf​/create​/html Convert HTML file (located on storage) to PDF format and return resulting file in response

​PUT /pdf​/{name}​/create​/html Convert HTML file (located on storage) to PDF format and upload resulting file to storage

GET ​/pdf​/storage​/{storageName}​/exist Check if storage exists

A post was split to a new topic: Convert HTML to PDF using Aspose.PDF REST API

The issues you have found earlier (filed as HTMLCLOUD-1750) have been fixed in this update. This message was posted using Bugs notification tool by andriy.radzikhovsky