PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 1:33 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Listview in pdf
PostPosted: Wed Jul 15, 2015 8:12 am 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
Good morning ,Sorry for my English , I used a translator :D. I'm making a program that makes a plan depreciation , once populated the listview , with PDFsharp I would like to export it to pdf . Let me explain how it should be then the listview:

RATA N. SCADENZA NETTO MENSILE INTERESSE MENSILE SPESE RATA MENSILE

1 10/07 200 7.50 10 217.50

2 10/08 200 7.50 207.50

3 10/09 200 7.50 207.50

each number under item ( rate: 1,2,3 - expiry : 10 / 07.10 / 08.10 / 09 .... and so on )

Once populated , I copy columns with the command , paste it in a column, so the code is the same , the position is changing :

e.DrawString(Me.Listview1.Columns(1).Text, font, XBrushes.Black, 120, 150)


and so far so good ; now the " problem " arises when I make the loop from 0 to the number of items that I want to paste ; I mean , the code works , namely :

e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 210)

But rightly it is doing the program ? I copy numbers of the first item one above the other, so in this case as in the example on the table above , copy me in the pdf at the position ,

50.210 numbers 1,2,3 .

The string of code now seems right , just missing the position , as I can " fix " ? Should I create another cycle but I should change the coordinates each item , how do I do ?

I hope I was clear , thank you for all your response and for your interest .


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Wed Jul 15, 2015 8:17 am 
Offline
PDFsharp Guru
User avatar

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

Sorry, I'm afraid I do not fully understand what the problem is. Maybe you can explain the problem better if you include screenshots.

MigraDoc supports tables and page breaks, so maybe this will be a better choice:
http://www.pdfsharp.net/wiki/Invoice-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Wed Jul 15, 2015 8:37 am 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
Hi
http://imageshack.com/a/img673/6822/DrEJrZ.jpg
http://imageshack.com/a/img673/1306/jOfLAf.png


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Wed Jul 15, 2015 12:53 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Your code writes all 10 data lines at the same PDF line.

Your header is at 150, all 10 data lines are at 210.
Increase the Y position with every new line (and be prepared to add new pages as needed).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Thu Jul 16, 2015 6:59 am 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
This is my code

Code:
Imports PdfSharp
Imports PdfSharp.Drawing
Imports PdfSharp.Pdf

Public Class Anteprima
    Dim fine As Integer
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        pdf()
    End Sub
    Sub pdf()
        Dim document As PdfDocument = New PdfDocument
        document.Info.Title = "Rateizzazione Sanzioni CdS"
        Dim page As PdfPage = document.AddPage
        page.Size = PdfSharp.PageSize.A4
        page.Orientation = PdfSharp.PageOrientation.Landscape
        Dim e As XGraphics = XGraphics.FromPdfPage(page)
        Dim font As XFont = New XFont("Arial", 14, XFontStyle.Regular)
        Dim fine As Integer = Listview1.Items.Count - 1
        For i As Integer = 0 To fine
                e.DrawString(Me.Label7.Text, font, XBrushes.Black, 50, 50)
                e.DrawString(Me.TextBox1.Text, font, XBrushes.Black, 130, 50)
                e.DrawString(Me.Label6.Text, font, XBrushes.Black, 50, 70)
                e.DrawString(Me.DateTimePicker4.Text, font, XBrushes.Black, 130, 70)
                e.DrawString(Me.Label5.Text, font, XBrushes.Black, 50, 90)
                e.DrawString(Me.DateTimePicker3.Text, font, XBrushes.Black, 130, 90)
                e.DrawString(Me.Listview1.Columns(0).Text, font, XBrushes.Black, 50, 150)
                e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 165)
                e.DrawString(Me.Listview1.Columns(1).Text, font, XBrushes.Black, 120, 150)
                e.DrawString(Me.Listview1.Items(i).SubItems(1).Text, font, XBrushes.Black, 120, 165)
                e.DrawString(Me.Listview1.Columns(2).Text, font, XBrushes.Black, 210, 150)
                e.DrawString(Me.Listview1.Items(i).SubItems(2).Text, font, XBrushes.Black, 210, 165)
                e.DrawString(Me.Listview1.Columns(3).Text, font, XBrushes.Black, 340, 150)
                e.DrawString(Me.Listview1.Items(i).SubItems(3).Text, font, XBrushes.Black, 340, 165)
                e.DrawString(Me.Listview1.Columns(4).Text, font, XBrushes.Black, 500, 150)
                e.DrawString(Me.Listview1.Items(0).SubItems(4).Text, font, XBrushes.Black, 500, 165)
                e.DrawString(Me.Listview1.Columns(5).Text, font, XBrushes.Black, 580, 150)
                e.DrawString(Me.Listview1.Items(i).SubItems(5).Text, font, XBrushes.Black, 580, 165)
            Next
            Dim filename As String = "Rateizzazione Sanzioni CdS.pdf"
            document.Save(filename)
            Process.Start(filename)
    End Sub
End Class


the user can not put only 10 lines , because you can put 2 to 60 lines . please help me :(


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Thu Jul 16, 2015 7:43 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
leviathan89 wrote:
please help me :(
The line "e.DrawString(Me.Label7.Text, font, XBrushes.Black, 50, 50)" and all other header lines should come before the for loop.

The line "e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 165)" should look like "e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 165 + 60 * i)". Same for other listview item lines.

The code that detects the end of the page and starts a new page is left as an exercise for the reader.
See also:
http://stackoverflow.com/a/21143712/162529

I wrote it before: try MigraDoc if one page is not enough. MigraDoc can even draw borders for you (if you want that).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Thu Jul 16, 2015 1:27 pm 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
Thats perfect!!! How can do a new page? If i have 10 Lines of listview, on pdf show 8 lines...automatic new page? How can do?


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Thu Jul 16, 2015 1:32 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Call AddPage() again. Draw the header again.
See also:
http://stackoverflow.com/a/21143712/162529

Or use MigraDoc.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Thu Jul 16, 2015 3:43 pm 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
Sorry i don't understand...im newbie... Where i put addpage? If i put
Page= document.addpage()
Xgraphics.frompdfpage(page)

Ad 10 page...he must add 2 page if serving 2 page...he add 3 page if serving 3 page...

Sorry, help me :(


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Fri Jul 17, 2015 8:15 am 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
This is my new code:

Code:
 Sub pdf()
        Dim document As PdfDocument = New PdfDocument
        document.Info.Title = "Rateizzazione Sanzioni CdS"
        Dim page As PdfPage = document.AddPage
        page.Size = PdfSharp.PageSize.A4
        page.Orientation = PdfSharp.PageOrientation.Landscape
        Dim e As XGraphics = XGraphics.FromPdfPage(page)
        Dim font As XFont = New XFont("Arial", 14, XFontStyle.Regular)
        Dim fine As Integer = Listview1.Items.Count - 1
        For i As Integer = 0 To fine
            e.DrawString(Me.Label7.Text, font, XBrushes.Black, 50, 50)
            e.DrawString(Me.TextBox1.Text, font, XBrushes.Black, 130, 50)
            e.DrawString(Me.Label6.Text, font, XBrushes.Black, 50, 70)
            e.DrawString(Me.DateTimePicker4.Text, font, XBrushes.Black, 130, 70)
            e.DrawString(Me.Label5.Text, font, XBrushes.Black, 50, 90)
            e.DrawString(Me.DateTimePicker3.Text, font, XBrushes.Black, 130, 90)
            e.DrawString(Me.Listview1.Columns(0).Text, font, XBrushes.Black, 50, 150)
            e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(1).Text, font, XBrushes.Black, 120, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(1).Text, font, XBrushes.Black, 120, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(2).Text, font, XBrushes.Black, 210, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(2).Text, font, XBrushes.Black, 210, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(3).Text, font, XBrushes.Black, 340, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(3).Text, font, XBrushes.Black, 340, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(4).Text, font, XBrushes.Black, 500, 150)
            e.DrawString(Me.Listview1.Items(0).SubItems(4).Text, font, XBrushes.Black, 500, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(5).Text, font, XBrushes.Black, 580, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(5).Text, font, XBrushes.Black, 580, 165 + 20 * i)
        Next
        Dim filename As String = "Rateizzazione Sanzioni CdS.pdf"
        document.Save(filename)
            Process.Start(filename)
    End Sub


This is the screenshoot http://imageshack.com/a/img633/2895/ldqb6l.png

I've put 60 rate but on pdf don't a new page.
If i do AddPage, add 10 page and don't copy the list view item. Sorry for my little english


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Mon Jul 20, 2015 5:37 pm 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
Thomas Hoevel wrote:
Call AddPage() again. Draw the header again.
See also:
http://stackoverflow.com/a/21143712/162529

Or use MigraDoc.



sorry Thomas Hoevel i don't understand...

Code:
            Sub pdf()
        Dim document As PdfDocument = New PdfDocument
        document.Info.Title = "Rateizzazione Sanzioni CdS"
        Dim page As PdfPage = document.AddPage
        page.Size = PdfSharp.PageSize.A4
        page.Orientation = PdfSharp.PageOrientation.Landscape
        Dim e As XGraphics = XGraphics.FromPdfPage(page)
        Dim font As XFont = New XFont("Arial", 14, XFontStyle.Regular)
        Dim fine As Integer = Listview1.Items.Count - 1
        For i As Integer = 0 To fine
            e.DrawString(Me.Label7.Text, font, XBrushes.Black, 50, 50)
            e.DrawString(Me.TextBox1.Text, font, XBrushes.Black, 130, 50)
            e.DrawString(Me.Label6.Text, font, XBrushes.Black, 50, 70)
            e.DrawString(Me.DateTimePicker4.Text, font, XBrushes.Black, 130, 70)
            e.DrawString(Me.Label5.Text, font, XBrushes.Black, 50, 90)
            e.DrawString(Me.DateTimePicker3.Text, font, XBrushes.Black, 130, 90)
            e.DrawString(Me.Listview1.Columns(0).Text, font, XBrushes.Black, 50, 150)
            e.DrawString(Me.Listview1.Items.Item(i).Text, font, XBrushes.Black, 50, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(1).Text, font, XBrushes.Black, 120, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(1).Text, font, XBrushes.Black, 120, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(2).Text, font, XBrushes.Black, 210, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(2).Text, font, XBrushes.Black, 210, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(3).Text, font, XBrushes.Black, 340, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(3).Text, font, XBrushes.Black, 340, 165 + 20 * i)
            e.DrawString(Me.Listview1.Columns(4).Text, font, XBrushes.Black, 500, 150)
            e.DrawString(Me.Listview1.Items(0).SubItems(4).Text, font, XBrushes.Black, 500, 165)
            e.DrawString(Me.Listview1.Columns(5).Text, font, XBrushes.Black, 580, 150)
            e.DrawString(Me.Listview1.Items(i).SubItems(5).Text, font, XBrushes.Black, 580, 165 + 20 * i)
        Next
        Dim page2 As PdfPage = document.AddPage
        page2.Size = PdfSharp.PageSize.A4
        page2.Orientation = PdfSharp.PageOrientation.Landscape

        Dim filename As String = "Rateizzazione Sanzioni CdS.pdf"
        document.Save(filename)
        Process.Start(filename)
    End Sub



If i add this code

Code:
        Dim page2 As PdfPage = document.AddPage
        page2.Size = PdfSharp.PageSize.A4
        page2.Orientation = PdfSharp.PageOrientation.Landscape


add a new page but don't continue the cycle. Where i wrong?


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview in pdf
PostPosted: Tue Jul 21, 2015 7:19 am 
Offline

Joined: Wed Jul 15, 2015 7:52 am
Posts: 8
thx i solved to reduce the font size 14 to 9.


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

All times are UTC


Who is online

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