PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sat Oct 11, 2025 9:49 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Apr 25, 2012 11:13 am 
Offline

Joined: Wed Apr 25, 2012 10:56 am
Posts: 3
Hi

Congratulation for Pdfsharp librery: it's the best! :D

In my application, Icreate small reports with pdfsharp and I save the file .pdf.. All things works good.
I would like to show my reports through pagepreview object
I write this test code:
Code:
Imports PdfSharp.Drawing
Imports PdfSharp
Imports PdfSharp.Forms
Imports System.Drawing

Public Class Form1
    Private mRenderEvent As PagePreview.RenderEvent
    Public WithEvents pdf As New RenderPdf

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'pg is pagepreview object in my main form

        Me.pg.SetRenderEvent(AddressOf pdf.render) 'delegate to sub render
        Dim pdfdocument As New PdfSharp.Pdf.PdfDocument
        Dim page As Pdf.PdfPage = pdfdocument.AddPage
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

        gfx.DrawString("EXAMPLE TEXT", New XFont("Arial", 20), Brushes.Black, 10, 10)

        pdf.render(gfx)
        pdfdocument.Save("prova.pdf")
    End Sub

    Private Sub SetRenderEvent(ByVal renderEvent As PagePreview.RenderEvent)
        Me.pg.SetRenderEvent(renderEvent)
        mRenderEvent = renderEvent
    End Sub

End Class

'renderpdf
Public Class RenderPdf
    Public Sub render(ByVal gfx As XGraphics)
        '??? what code?
    End Sub
End Class

This code has no errors but the object pg does not display the text.
How to display the document you created in the preview?

Thank you.

PS: sorry for my english :lol:


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 27, 2012 7:23 am 
Offline

Joined: Wed Apr 25, 2012 10:56 am
Posts: 3
Hi!
Can anyone help me?

How do modify the Xgraphics object in render sub?
Something like this:
Code:
Public Sub renderPage(ByVal RenderGfx As PdfSharp.Drawing.XGraphics)

       Dim document As New PdfDocument(filename)
       Dim page As PdfPage = document.AddPage()
       page.Size = PageSize.A4
       RenderGfx = XGraphics.FromPdfPage(page)
       RenderGfx .DrawString("text", New XFont("Arial", 20), Brushes.Black, 20, 20)
       RenderGfx.Save()
End Sub

I would like show in preview my document...


Top
 Profile  
Reply with quote  
PostPosted: Wed May 02, 2012 8:01 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Hi!

Simple trick: use the XGraphics object that is passed as a parameter to your Render routine, don't assign a new value.
For screen preview, you will receive an XGraphics object that draws on the screen.

See the complete source code of the Preview sample (C# only) for further details. The Wiki only shows a snippet, but the complete source code is included in the sourcecode package.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 03, 2012 7:33 am 
Offline

Joined: Wed Apr 25, 2012 10:56 am
Posts: 3
Hi!

thank you for responding! :)
Well, I study the sample preview project attached the dll library and I understand the process.
But, In my application I create a complex PDF of 3 pages with pfdSharp (for frame box) and MigraDoc (for table).

Is there a way to show the complete document?
some trick?

How to use the same XGraphics object for multipage document?

Thank you! :)


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 423 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