Export SPA page to PDF

Hello,

I’m trying to export a single page application URL to pdf. The problem is that it’s always blank because the page has not been fully loaded. However the static texts that are in the Body are put into the pdf file. I’ve also tested with the static html page from the example(Convert HTML to PDF in .NET|Aspose.PDF for .NET) and it’s working fine.
I can’t find any examples for dynamic web pages that are not using static html. Am I missing something?
Is it possible to export a page with Aspose where I have a bunch of xhr requests to PDF? If so is there a way with or without timeouts?

Here’s a piece of code that I’m using:
var contentFromUrlAsStream = httpClient.GetStreamAsync( baseAddress ).GetAwaiter().GetResult();
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document( contentFromUrlAsStream, new HtmlLoadOptions( baseAddress ));
In this case the baseAdress is pointing to our Angular app.

Thank you,
Nikolay

@nikolai.ivanov17

Could you please share the sample link from which you want to generate a PDF document along with recently generated and expected output PDFs. We will test the scenario in our environment and address it accordingly.

Furthermore, you can try using the below code snippet as well in order to convert a webpage into PDF:

var url = "{URL to Webpage}";
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
// If required by the server, set the credentials.
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Time out in miliseconds before the request times out
request.Timeout = 1000;
// Get the response.
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
      
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions(dataDir + "Personnel_files\\");
options.PageInfo.IsLandscape = false;
options.PageInfo.Margin = new MarginInfo() { Bottom = 35, Left = 35, Right = 35, Top = 35 };
options.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;
options.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;
// Load HTML file
Document pdfDocument = new Document(stream, options);
// Save output as PDF format
pdfDocument.Save(dataDir + "WebpageToPdf.pdf");

Hello Asad,

Thank you very much for the fast response. I tried the code that you posted above. Unfortunately the result was the same - empty page.

Here’s a sample link that I’m trying to export: SMART Platform
Aspose result:
aspose_result.pdf (68.7 KB)

Expected result:
expected_result.pdf (41.9 KB)

I hope that it helps. Please let me know if you need any additional information.
It’s vital for us to see if Aspose can generate the pdf since we have multiple different reports generated from angular pages that take different time to load.

Thank you

@nikolai.ivanov17

We were able to notice the issue at our end while testing the scenario. We have noticed that the HTML content was JavaScript based and respective JS was not executed properly during conversion. We have logged an issue as PDFNET-49301 in our issue tracking system for further investigation. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We apologize for the inconvenience.

1 Like

Thank you, Asad. We’ll buy the Aspose.Total package only if the issue is fixed.
It’s a showstopper for us since we have a lot of reports. Could you please give me an effort estimation on how long it will take for the issue to be fixed and to go live.

@nikolai.ivanov17

Please note that the issues in free support model are resolved on a first come first serve basis. Also, the API is currently unable to execute JavaScript calls during HTML to PDF conversion. Adding support of such functionality to the API involves a lot of work and it is certainly time taking. We sadly cannot promise any definite timeline for this feature to be added in the API. However, we have recorded your concerns and will surely consider them during ticket investigation.

We will further inform you in this forum thread as soon as we have some definite updates regarding ticket resolution. Please give us some time.

We apologize for the inconvenience.