Articles in this section
Category / Section

How to use WindowStatus in HTML converter For .NET WebForms PDF?

2 mins read

We can manually wait HtmlConverter up to the document loading using WindowStatus property in HTML converter. We can use windows status instead of addition delay. In additional delay, we do not know the exact time that need for execution of JavaScript. By windows status you can avoid this problem.

Note:

Both window status should be same, else converter never stops the conversion

Assemblies Required

1)Syncfusion.Compression.Base.dll

2)Syncfusion.HtmlConverter.Base.dll

3)Syncfusion.Pdf.Base.dll

Steps to use WindowStatus in HTML converter programmatically in c#:

1)Create a new WPF application project.

Create a new WPF application project in WinForms PDF

2)Install the Syncfusion.HtmlToPdfConverter.WPF NuGet package as reference to your .NET Framework applications from NuGet.org.

Install NuGet packages in WinForms PDF

3)Include the following namespaces in the MainWindow.xaml.cs file

 using Syncfusion.HtmlConverter;
 using Syncfusion.Pdf; 
 using System.Windows;

 

Add a new button in MainWindow.xaml to create a PDF document as follows.

 

<TextBlock TextAlignment="Justify" FontFamily="Verdana" FontSize="11" TextWrapping="Wrap" Padding="5,5,5,5" Margin="0,77,0,1" >
<TextBlock.Background>
<LinearGradientBrush EndPoint="0.5,-0.04" StartPoint="0.5,1.04">
<GradientStop Color="#FFD9E9F7" Offset="0"/>
<GradientStop Color="#FFEFF8FF" Offset="1"/>
</LinearGradientBrush>
</TextBlock.Background>
<TextBlock.Text>
Click the button to view PDF file generated by Essential PDF.
</TextBlock.Text>
</TextBlock>
<Button Click="btnCreate_Click" Margin="0,0,10,12" VerticalAlignment="Bottom" Height="30" BorderBrush="LightBlue" HorizontalAlignment="Right" Width="180">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,-0.04" StartPoint="0.5,1.04">
<GradientStop Color="#FFD9E9F7" Offset="0"/>
<GradientStop Color="#FFEFF8FF" Offset="1"/>
</LinearGradientBrush>
</Button.Background>
<StackPanel Orientation="Horizontal" Height="23" Margin="0,0,0,-2.52" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="100">
<Image Name="image2" Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text="Create PDF" Height="15.96" Width="126" Margin="0,4,0,3" />
</StackPanel>
</Button>

 

Add the following code in btnCreate_Click to create a PDF file with simple text.

           C#

// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
 
//Set window status
blinkConverterSettings.WindowStatus = "completed";
htmlConverter.ConverterSettings = blinkConverterSettings;
//Convert url to pdf
PdfDocument document = htmlConverter.Convert("input.html");
 
//Save the document.
document.Save("Sample.pdf");

 

           Input.html

<html>
<head>
 
</head>
<body >
    <div id="message">
        Wait for 2 Seconds
    </div>
   
    <script type="text/javascript">
        
        setTimeout(function () {
            document.getElementById("message").innerHTML = "Hello World!!";
            window.status = "completed";
        }, 2000);
    </script>
 
</body>
</html>

 

     A complete working sample can be downloaded from WindowStatus.zip.

     By executing the program, you will get the PDF document as follows.

                               WinForms PDF document

 

 Take a moment to peruse the documentation, where you can find converting HTML pages to PDF document along with respective customization options and features.

 Refer here to explore the rich set of Syncfusion Essential PDF features.

 An online sample link to convert HTML to PDF document.

Note:

A new version of Essential Studio for ASP.NET is available. Versions prior to the release of Essential Studio 2014, Volume 2 will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential Studio for JavaScript providing client-side rendering of HTML 5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.

The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential Studio for ASP.NET. Although Syncfusion will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.

You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied