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:28 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Thu Jul 09, 2015 4:09 pm 
Offline

Joined: Thu Jul 09, 2015 3:46 pm
Posts: 3
I want to call the render code manually, ie not activated by an event

I can do this with standard forms objects like a RichTextBox:

Dim myGraphics As Graphics = RichTextBox1.CreateGraphics
Dim mysize As XSize : mysize.Height = 300: mysize.Width = 300
Dim gfx As XGraphics = XGraphics.FromGraphics(myGraphics, mysize)
Call myrender(gfx)


And myrender draws the image correctly on the target.

How do I do this with the PagePreview?

trying:

Dim myGraphics As Graphics = PagePreview1.CreateGraphics

Does not throw up any errors, but the image does no appear.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 10, 2015 10:48 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 343
Andrew1 wrote:
I want to call the render code manually, ie not activated by an event
Why?

PagePreview calls a render routine supplied by you.
Why not call this routine directly without PagePreview in between?
Create a Graphics object for your target, encapsulate it in an XGraphics object and call your render routine.

If you think there is an error in PDFsharp then please provide an SSCCE.
See also:
viewtopic.php?p=2094#p2094

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 10, 2015 8:02 pm 
Offline

Joined: Thu Jul 09, 2015 3:46 pm
Posts: 3
Thanks for your reply.

>>>> Why?

Because I am trying to understand the code in the example "Preview"

In the example I can see how the graphics object from the printer or the pdf page is obtained, with code like:

Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim graphics As Graphics = ev.Graphics
graphics.PageUnit = GraphicsUnit.Point
Dim gfx As XGraphics = XGraphics.FromGraphics(graphics, PageSizeConverter.ToSize(PageSize.A4))
.......

But I can't see how the graphics object is got for the PagePreview.
I don't see gfx being assigned when the PagePreview is used.

I thought I would first obtain the graphics object for the PagePreview by hand, and call the renderer manually.
And then transfer it into an PagePreview event handler.
This would help me understand what the code is doing.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 13, 2015 2:28 pm 
Offline

Joined: Thu Jul 09, 2015 3:46 pm
Posts: 3
I never did manage to separate out the page preview graphics object, I just got the code working as in the sample.

But incase it helps other people trying to understand the code, here is what I found:

A) the page preview control automatically calls the render event when the zoom level changes or the scroll bars are used, or the size of the page preview changes. I was puzzled by the lack of an invalidate call in the sample zoom routine... this is why.


B) I could not see the mechanism that creates a graphics object (gfx) so that the render can be called, but it is in the property.set shown below, which is called one time during the form load.

Friend Myrenderevent As PagePreview.RenderEvent

Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RenderEvent = New PagePreview.RenderEvent(AddressOf myrender)
End Sub

WriteOnly Property RenderEvent() As PagePreview.RenderEvent
Set(ByVal value As PagePreview.RenderEvent)
pagePreview.SetRenderEvent(value)
Myrenderevent = value
End Set
End Property


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 42 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