We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it possible to convert an html string to PDF in XF

Thread ID:

Created:

Updated:

Platform:

Replies:

141392 Dec 10,2018 06:16 AM UTC Feb 4,2019 09:11 AM UTC Xamarin.Forms 10
loading
Tags: PDF
Reihaneh Khaksaran
Asked On December 10, 2018 06:16 AM UTC

Hello,

I'm using XAmarin.Forms and just wanted to know if it's possible to convert an html string to PDF (not a URL to pdf, just an HTML string) using syncfusion?

Thanks,

Reihaneh


Karthik Krishnaraj [Syncfusion]
Replied On December 11, 2018 12:43 PM UTC

Hi Reihaneh,  
 
Thanks for contacting Syncfusion support.   
 
Currently we do not have native support for converting URL/ HTML string to PDF in Xamarin Forms. As a workaround, we can convert URL/HTML string to PDF in Xamarin using Web Service. Please refer below KB link for sample and code snippet for converting HTML to PDF in Xamarin using web service,     
KB:  
 
Kindly refer below UG and KB links for converting HTML string to PDF.    
UG:  
KB:  
 
Please let us know if you need any further assistance on this.   
 
Regards, 
Karthik. 


Reihaneh Khaksaran
Replied On December 15, 2018 03:59 PM UTC

Hi,

Thank you so much for your reply, one more question, what dlls should I add to my project? I mean according to the samples, I must add Syncfusion.Pdf.Base, Syncfusion.Compression.Base and Syncfusion.HtmlConverter.Base, is thath coorect? and I also have installed Syncfusion Essential Studio, but I can't find any of these dlls anywhere in my computer, is there anything else I should download and install?

Thanks,
Reihaneh

Karthikeyan Chandrasekar [Syncfusion]
Replied On December 17, 2018 06:26 AM UTC

Hi Reihaneh, 
Yes, you should install the WebKit installer to get the required assemblies. Please refer the prerequisites to get the details. 

Revert me back if you need any additional information. 
Regards, 
Karthikeyan  


Reihaneh Khaksaran
Replied On December 17, 2018 01:53 PM UTC

Hi,

Thank you, I downloaded and added the following assemblies:

Syncfusion.Compression.Portable
Syncfusion.HtmlConverter.Portable
Syncfusion.Pdf.Portable

but after running the code below,

        public MemoryStream CreateDocument(string pathURL)
        {
            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();

            //Initialize the WebKit settings
            WebKitConverterSettings webKitSettings = new WebKitConverterSettings();

            //Set the webKit path
            webKitSettings.WebKitPath = "../QtBinaries/";

            //Set the WebKit conversion settings
            htmlConverter.ConverterSettings = webKitSettings;

            //Convert url to pdf
            MainPage.stateSequencerController.GenerateHTML();
            PdfDocument document = htmlConverter.Convert(pathURL);

            //Save the document
            MemoryStream stream = new MemoryStream();

            document.Save(stream);

            //Sets the stream position
            stream.Position = 0;

            //Close the PDF document
            document.Close();

            //Return the PDF stream.
            return stream;

        }

I get this exception:
Unhandled Exception:

System.TypeLoadException: Could not load type of field 'Syncfusion.HtmlConverter.WebKitConverterSettings:m_toc' (18) due to: Could not resolve type with token 01000011 (from typeref, class/assembly Syncfusion.Pdf.HtmlToPdf.HtmlToPdfToc, Syncfusion.Pdf.Portable, Version=16.4200.0.40, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89) assembly:Syncfusion.Pdf.Portable, Version=16.4200.0.40, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89 type:Syncfusion.Pdf.HtmlToPdf.HtmlToPdfToc member:(null) signature:<none> occurred

Can you please help me with this?

Thanks,
Reihaneh

Karthikeyan Chandrasekar [Syncfusion]
Replied On December 18, 2018 11:13 AM UTC

Hi Reihaneh 
As mentioned in our earlier update () we do not have support for HTML to PDF in Xamarin platform. You can use it only by creating the web service of your own. Web service will be created in .NET Framework and the endpoints will be used for the conversion in Xamarin application. Please refer the KB article for the samples. The following assemblies should be referred in the Web Service application. 
Syncfusion.Compression.Base 
Syncfusion.HtmlConverter.Base 
Syncfusion.Pdf.Base 

Regards, 
Karthikeyan  


Reihaneh Khaksaran
Replied On December 24, 2018 02:14 PM UTC

Hi,

So all I need to do is create a web service? Is there any guide on that?

Thank you

Karthikeyan Chandrasekar [Syncfusion]
Replied On December 26, 2018 04:42 AM UTC

Hi Reihaneh, 
Yes, you need to create a web service, please find the working sample in the below link. 
 
Revert me back if you need any further assistance in this. 
Regards, 
Karthikeyan  


Reihaneh Khaksaran
Replied On January 28, 2019 09:47 AM UTC

Hi,

I have downloaded this sample

but when I try to run it, I get the following exception:

Unhandled Exception:
System.Net.WebException: Error: ConnectFailure (Connection refused) occurred

Could you please tell me what I'm doing wrong?

Best regards,
Reihaneh

Reihaneh Khaksaran
Replied On February 2, 2019 06:59 AM UTC

Hi,

I have downloaded this sample

but when I try to run it, I get the following exception:

Unhandled Exception:
System.Net.WebException: Error: ConnectFailure (Connection refused) occurred

Could you please tell me what I'm doing wrong?

Best regards,
Reihaneh

Hi,

Could you please help me with this issue?

Thank you

Karthikeyan Chandrasekar [Syncfusion]
Replied On February 4, 2019 09:11 AM UTC

Hi Reihaneh, 

This exception may occurs if the service is not reachable from the device. If you are using local host URL as web reference in the Xamarin application then this exception may occurs due to the service is not reachable. If you are using localhost URL, then the device will actually trying to connect the device itself not to your desktop/server. If you want to connect the service from desktop/server, then you to host the service in the desktop/server then you need to use the IP address of the target machine.  

Note: We have ensured this by hosting the service in IIS and then provided the complete service URL in the Xamarin application.  
Regards, 
Karthikeyan  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;