PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 10:42 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: MigraDoc Bulleted Lists
PostPosted: Mon Apr 08, 2013 6:46 pm 
Offline

Joined: Mon Apr 08, 2013 3:26 pm
Posts: 3
Hello,

Firstly, thank you for all the work you do on PdfSharp/MigraDoc. It is an immensely useful tool.

I am trying to figure out 2 things relating to MigraDoc bulleted lists. I am rendering to PDF.

1) Is there a way to control on the gap between the bullet and the item text? I thought it was controlled by the value of Style.ParagraphFormat.LeftIndent, but maybe I am using it incorrectly?

2) Is there a way to control the default wrap for the item text? I seem to be getting a default wrap at approximately 1 inch in width. I tried to find some way of controlling the wrap in the object model, but couldn't figure one out.

I am using Visual Studio 2005, MigraDoc version 1.31.3066.0, and PdfSharp version 1.31.1789.0, GDI+, which I am sort of tied to since I have a lot of other code dependent on it, that I don't wish to retest.

The code is a console app that I created (sorry for the style, C# is not my native language) to illustrate the problem situations that are prompting my questions. The initial purpose of the app was to displays the item list using each of the 6 bullet types, staggered down the page, as I wanted to visually see the bullet produced for each bullet type in the ListType enumeration.

The command line parameters to the console app are:
FileNameToCreate VerticalBarSeparatdItemList LeftIndentWidthInInches XIncrementalValueInInches YIncrementalValueInInches

Run #1 Parameters: "C:\TestMigraDocBulletsRun1.Pdf" "Item1|Item2|Item3|Item4|Item5|Item6" 0.25 0.125 1.25

Run #2 Parameters: "C:\TestMigraDocBulletsRun2.Pdf" "Item1|Item2|Item3|Item4|Item5|Item6" 0.5 0.125 1.25

Run #3 Parameters: "C:\TestMigraDocBulletsRun3.Pdf" "A wide Item Number 1|A wide Item Number 2|A wide Item Number 3|A wide Item Number 4|A wide Item Number 5|A wide Item Number 6" 0.25 0.125 1.25

Run#1 looks good, it's how I wanted the other two runs to look.

Run#2 tries to increase the width between the bullet and text, from 0.25 inches to 0.5 inches, which had the opposite effect. The gap between the bullet and text disappeared. Not sure what I'm doing wrong.

Run#3 used more "reasonable" item text. The 1 inch (approx) wrap came as an unpleasant surprise. The real item text for my production lists will be several lines long.

My production code has components that do some editing using PdfSharp, so I needed to be able to support the mixed PdfSharp/MigraDoc model that the example code does. A fixed "RenderBullets" routine would need to work with a passed in XGraphics object.

Thanks in advance if you are able to help/clarify in any way.

Butler.


Attachments:
File comment: This contains the PdfSharp binary my project was referring to. Added because you wanted a project you can compile and run.
References2.zip [214.51 KiB]
Downloaded 373 times
File comment: This contains the PdfSharp.Charting, MigraDoc and MigraDoc.Rendering binary references
References1.zip [169.23 KiB]
Downloaded 380 times
File comment: This is my code, the solution and my example problem PDFs.
MigraDocBulletsExample.zip [24.87 KiB]
Downloaded 388 times
Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 08, 2013 10:02 pm 
Offline

Joined: Mon Apr 08, 2013 3:26 pm
Posts: 3
So I resolved the problem from Run#3, by adding an explicit Width to the TextFrame. Didn't realized it gets created with a default width of 1 inch, which was causing the wrap.


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 08, 2013 10:25 pm 
Offline

Joined: Mon Apr 08, 2013 3:26 pm
Posts: 3
I was able to fix the problem from Run#2 by properly applying the example code from:

http://stackoverflow.com/questions/9633135/migradoc-bullet-list-holes

So I have no outstanding issues.

Butler.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 12:50 pm 
Offline

Joined: Tue Jan 07, 2014 7:35 pm
Posts: 12
I am going through all the posts I can find to figure out using bullet lists.

I am creating a document that uses PDFSharp and MigraDoc together.

Here is how I am rendering paragraph by paragraph right now:

Code:
Dim docRenderer As DocumentRenderer = New DocumentRenderer(doc)
        docRenderer.PrepareDocument()
        docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(22.225), "18cm", eligReq)
        docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(36.5), "18cm", partElg)
        docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(41.275), "18cm", para2)
        docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(65.0875), "18cm", para3)


I am rendering like this so I can control where the paragraphs appear on the page (I might be doing it wrong, I don't know for sure).

Now I am ready to add bulleted lists of items in my document and realize that I don't know how to render them using the technique I have been using up to now. Normally, I render paragraph by paragraph, but in a bullet list, I have several paragraphs making up my bullet list, like this:

Code:
 Dim idx As Int32

        For idx = 0 To listItems1.Count - 1
            Dim listInfo As ListInfo = New ListInfo()
            listInfo.ContinuePreviousList = (idx > 0)
            listInfo.ListType = ListType.BulletList1
            Dim addPar As Paragraph = sec.AddParagraph(listItems1.Item(idx))
            addPar.Style = "bullet1"
            addPar.Format.ListInfo = listInfo
        Next


As you can see, I am manually moving each paragraph down the page of the document by setting the XUnit values for "Y".

e.g. docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(41.275), "18cm", para2)
docRenderer.RenderObject(gfx, XUnit.FromMillimeter(22.225), XUnit.FromMillimeter(65.0875), "18cm", para3)

Obviously, this isn't going to work for the paragraphs in the bullet list. Any advice?

Thank you,

Randy


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 1:26 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
RandyHJ57 wrote:
Any advice?
I hope you have a good reason for taking such a complicated approach. You could simply let MigraDoc create the PDF for you and MigraDoc would position the bullet list items where they belong.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 1:35 pm 
Offline

Joined: Tue Jan 07, 2014 7:35 pm
Posts: 12
I am doing it this way because I have to place a bordered rectangle with text inside it on the right side of my document that covers several lines. So I am using PDFSharp to draw my header, footer and the bordered rectangle in an exact position.

Then I am using MigraDoc to place the text of my document inside at the proper position in relation to my bordered rectangle.

I am doing it this way because it was the only way I could figure out to make it work after reviewing all the samples and searching this forum and StackOverflow.

When I simply added a paragraph in MigraDoc, it rendered it directly over the previous paragraph, so I moved the 'Y' position in my render command.


Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 2:01 pm 
Offline

Joined: Tue Jan 07, 2014 7:35 pm
Posts: 12
Here is an image of my letter format:

Are you saying I can do all of this in MigraDoc without using PDFSharp?

The bullet lists I need to make on on Page 2 of this document.


Attachments:
sampleletter.png
sampleletter.png [ 8.42 KiB | Viewed 8369 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed May 24, 2017 2:34 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
RandyHJ57 wrote:
Are you saying I can do all of this in MigraDoc without using PDFSharp?
I think so.
You can use objects of the TextFrame class for absolute positions.
Your code is responsible to prevent TextFrame contents from overlapping each other or contents of the main body of the document. And TextFrame contents do not break to the next page.

A letter head with address and contact information should be no problem because the lengths of the contents at absolute positions are very similar.

MigraDoc is much like Word. Design the letter head as you would with Word.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu May 25, 2017 10:41 am 
Offline

Joined: Tue Jan 07, 2014 7:35 pm
Posts: 12
Ok, I have taken your advice and switched over to trying to do this with MigraDoc.

I have two issues:

#1. I am having problems positioning my TextFrame objects vertically on the page.
Code:
'Add footer to document
        Dim footer As HeaderFooter = sec.Footers.FirstPage
        Dim s1 As TextFrame = footer.AddTextFrame()
        Dim s2 As TextFrame = footer.AddTextFrame()

        s1.WrapFormat.Style = WrapStyle.None
        s1.RelativeVertical = RelativeVertical.Page
        s1.WrapFormat.DistanceBottom = New Unit(1.27, UnitType.Centimeter)
        s1.Top = "26.67cm"
        s1.Left = New Unit(-1.27, UnitType.Centimeter)
        s1.Width = New Unit(12.6, UnitType.Centimeter)
        s1.AddParagraph("P.O. Box 69184, Harrisburg, PA 17106-9184 | M-F 8AM to 9PM(ET) | ")

        's2.Left = New Unit(8.25, UnitType.Centimeter)
        's2.AddImage("C:\MigraDoc\MigraDocPractice\MigraDocPractice\images\phone.png")


How do I set the vertical position of the TextFrames to 1.27cm above the bottom of the page?
How can I draw a horizontal line across the page above my TextFrame footer text with MigraDoc?

#2. Can I draw a rectangle, like the one in the image I posted above with text inside, just using MigraDoc (TextFrame or something else, what?)?


Top
 Profile  
Reply with quote  
PostPosted: Fri May 26, 2017 6:27 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
You can draw paragraphs with just a top border to create a horizontal line.
You can draw paragraphs with a border on all sides to create a rectangle around it.

With respect to position: I don't know which property is correct. You can try "Top", you can try "WrapFormat.TopDistance" or "BottomDistance", maybe more.
See this post, positioning some images:
viewtopic.php?p=9038#p9038

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Wed May 31, 2017 1:20 pm 
Offline

Joined: Tue Jan 07, 2014 7:35 pm
Posts: 12
Thank you all for your responses.


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 159 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