WkHtmlToPdfConverter - Error
-
Friday, March 02, 2012 9:22 AM
Try Dim myByteArray() As Byte Using myHTMLToPDF As New Agresso.Students.HtmlToPDFCpnvertor.WkHtmlToPdfConverter() myByteArray = myHTMLToPDF.Convert(myHTML) myHTMLToPDF.Dispose() End Using Dim myOutputData As String = Path.GetTempPath + DateTime.Now.ToShortDateString().Replace("/", "_") + DateTime.Now.ToShortTimeString().Replace(":", "_") + DateTime.Now.Second.ToString() + ".PDF" Using myStream As New System.IO.FileStream(myOutputData, System.IO.FileMode.Create) myStream.Write(myByteArray, 0, myByteArray.Length) myStream.Close() myStream.Dispose() End Using Return myOutputData Catch End TryHi Guys,
I am using the above code to generate a PDF document based on a specific html string. The code works perfectly for the first time, however when I run the same code for the second time it generates a PDF document which has all the html formatting removed. The second PDf produced only ocontains one large block of text.
I assume there is a problem disposing of the object after the first use? has anyone else had a similar problem with this?
Thank you and eagerly await your reply.
Kelvin
Kind regards, Kelvin
- Moved by Leo Liu - MSFT Monday, March 05, 2012 5:20 AM Moved for better support. (From:Visual C# General)
All Replies
-
Monday, March 05, 2012 5:21 AMHi Kelvin,
I am moving your thread into the Visual Basic General Forum for dedicated support.
Have a nice day,Leo Liu [MSFT]
MSDN Community Support | Feedback to us
-
Wednesday, March 07, 2012 10:53 AMModerator
Hi Kelvin,
Your code didn't show how do you convert the html text to PDF.
Anyway, please take a look at this similar thread about how to convert html to PDF
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/86e4cbee-17ef-47cd-b476-30e8ae053d1d/
And here is another code project: http://www.codeproject.com/Articles/7089/Generate-PDF-documents-from-a-HTML-page-using-ASP Although it is a asp.net sample, but the function of this topic is also available in Windows Form. And this online translate tools can help you to convert the C# code to VB. If you have any further concerns, please feel free to follow up.
I hope this will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Wednesday, March 14, 2012 9:30 AMModerator
Hi Kevin,
I don't hear from you a couple of days.
Do you have any update?
How about your issue now?
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Wednesday, March 14, 2012 9:33 AM
Mike,
Sorry for the late reply, I jave been busy (and to be honest I forgot :( ). To resolve the issue above I changed the cod3e to the following:
Public Function GenerateHardcopyPDF(ByVal myHTML As String) As String Try Dim myByteArray() As Byte 'Dim myHTMLToPDF As New Agresso.Students.HtmlToPDFCpnvertor.WkHtmlToPdfConverter() Dim myHTMLToPDF As IHtmlToPdfConverter = New MultiplexingConverter() myHTMLToPDF.ObjectSettings.Load.LoadErrorHandling = Agresso.Students.HtmlToPDFCpnvertor.LoadErrorHandlingType.ignore myByteArray = myHTMLToPDF.Convert(myHTML) Dim myOutputData As String = Path.GetTempPath + DateTime.Now.ToShortDateString().Replace("/", "_") + DateTime.Now.ToShortTimeString().Replace(":", "_") + DateTime.Now.Second.ToString() + ".PDF" Using myStream As New System.IO.FileStream(myOutputData, System.IO.FileMode.Create) myStream.Write(myByteArray, 0, myByteArray.Length) myStream.Close() myStream.Dispose() End Using Return myOutputData Catch End Try End FunctionThis resolved the issue :)
Thank you for your help.
Kelvin
Kind regards, Kelvin
- Marked As Answer by Mike FengMicrosoft Contingent Staff, Moderator Wednesday, March 14, 2012 9:49 AM
-
Wednesday, March 14, 2012 9:49 AM
Kevin,
And you took that DLL from a link from Mike, then pleas tell which link, mark the reply from Mike as answer and also yours.
Success
Cor- Edited by Cor LigthertMVP Wednesday, March 14, 2012 9:50 AM

