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 Dec 26,2018 04:42 AM UTC Xamarin.Forms 7
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

KarthikeyanC [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

KarthikeyanC [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

KarthikeyanC [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  


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

or the page will be automatically redirected to 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

;