PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Display Gauge for Documentrenderer.preparedocument Progress https://forum.pdfsharp.net/viewtopic.php?f=2&t=1914 |
Page 1 of 1 |
Author: | Portman [ Fri Feb 17, 2012 12:11 pm ] |
Post subject: | Display Gauge for Documentrenderer.preparedocument Progress |
Hello I have a vb.net program calling migradoc 1.31 that create a PDF file correctly, I have created 2 versions one using PdfDocumentRenderer and other DocumentRenderer. I am now trying to add code to display a progress bar to show progress in rendering a pdf document and am now confused so dont know if you can help. the forum entry viewtopic.php?f=2&t=1654&p=4645 refers to PdfDocumentRenderer.DocumentRenderer.PrepareDocumentProgress but viewtopic.php?f=2&t=773& refers to PrepareDocumentProgress event of DocumentRenderer and includes a short example in c# I think that I must use DocumentRenderer but am having trouble understanding the calls required to get progress. I have code as below based on the sample but trouble is in defining correct parameter to myhandler and then using it Code: Dim docRenderer As MigraDoc.Rendering.DocumentRenderer docRenderer = New DocumentRenderer(document) Dim ProgressCompleted, ProgressPrepare As Integer Dim fe As New DocumentRenderer.PrepareDocumentProgressEventArgs(ProgressCompleted, ProgressPrepare) ProgressCompleted = 5 ProgressPrepare = 95 ' Dim myhandler As New DocumentRenderer.PrepareDocumentProgressEventHandler(AddressOf docRenderer) docRenderer.PrepareDocument() ' now create pdf pages Dim i, npages As Integer npages = docRenderer.FormattedDocument.PageCount ProgressBar1.Maximum = npages Any help appreciated or an extended sample of the c# in the post above Many Thanks C |
Author: | Portman [ Sat Feb 18, 2012 5:20 pm ] |
Post subject: | Re: Display Gauge for Documentrenderer.preparedocument Progress |
Hi Stepping back for a night helps!! ![]() Got desired result by amending code as follows - Code: Dim docRenderer As MigraDoc.Rendering.DocumentRenderer docRenderer = New DocumentRenderer(document) ' Addhandler to update progressbar AddHandler docRenderer.PrepareDocumentProgress, AddressOf UpdateBar docRenderer.PrepareDocument() and then adding the handler subroutine Code: ' UpdateBar has the same signature as PrepareDocumentProgressEventHandler. Public Sub UpdateBar(ByVal sender As Object, ByVal e As DocumentRenderer.PrepareDocumentProgressEventArgs) Me.ProgressBar1.Maximum = e.Maximum Me.ProgressBar1.Value = e.Value Me.TextBox1.Text = "Preparing PDF Page " & e.Value.ToString System.Windows.Forms.Application.DoEvents() End Sub Not sure if this the most elegant but it worked. Also limited test showed that total elapsed time to create my 24page pdf file was almost same whether I used docrenderer with preparedocument and then renderpage or PdfDocumentRenderer with PrepareRenderPages and Renderpages or PdfDocumentRenderer with Renderdocument First option has advantage of showing progress in a long running document |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |