PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 11:32 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Feb 17, 2012 12:11 pm 
Offline

Joined: Fri Feb 17, 2012 10:35 am
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 18, 2012 5:20 pm 
Offline

Joined: Fri Feb 17, 2012 10:35 am
Posts: 2
Hi
Stepping back for a night helps!! :D
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 44 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group