0

I have got a dynamic text, which has an unknown number of lines. This number of lines can be between 1 and for example 1000. Now I want do create a PDF document, which automatically creates a new page if a specific number of lines is reached.

I already found that it would probably work with MigraDoc, but I tested it already and well.. it didn't work like I tested it.

        // You always need a MigraDoc document for rendering.

        Document doc = new Document();

        MigraDoc.DocumentObjectModel.Section sec = doc.AddSection();

        // Add a single paragraph with some text and format information.

        MigraDoc.DocumentObjectModel.Paragraph para = sec.AddParagraph();       
        para.Format.Alignment = ParagraphAlignment.Justify;       
        para.Format.Font.Name = "Times New Roman";       
        para.Format.Font.Size = 12;        
        para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;      
        para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;    
        para.AddText("Duisism odigna acipsum delesenisl ");        
        para.AddFormattedText("ullum in velenit", TextFormat.Bold);      
        para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " +           
        "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " +
        "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent \nA \n B\nV \nD \nE\nF\nG\nA \n B\nV \nD \nE\nF\nG\nA \n B\nV \nD \nE\nF\nG\nA \n B\nV \nD \nE\nF\nG\nA \n B\nV \nD \nE\nF\nGnit ipis et nonsequis " +           
        "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " +        
        "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠");       
        para.Format.Borders.Distance = "5pt";         
        para.Format.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Gold;
        // Create a renderer and prepare (=layout) the document
        MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);           
        docRenderer.PrepareDocument();

This is the code I took from a MigraDoc example, but it doesn't really work as I want. Instead of creating a new page after the appropiate number of lines, it just writes further out of the border of the first page.

Can you give me an example where multiline text creates a new page if the appropiate number of lines ist reached?

Benziner
  • 43
  • 6
  • Well, the problem is that this text is only an example to test long text. In a real example were would just be a variable instead of the text but it could also be as long as this text. Do I have to split this text each time? And if yes how can I do this for varying line numbers? I am using Migradoc 1.32 – Benziner Nov 16 '16 at 06:45

1 Answers1

0

To create a PDF document from MigraDoc, use the PdfDocumentRenderer class and you will get as many pages as needed.

A sample can be found here:
http://www.pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

The class DocumentRenderer you are using is for special cases. By design, it cannot handle page breaks automatically.

  • Well that is exactly what doesn't help me. The examples are too large and there are too many problems, which I have to focus on until it really works. Can you just give me a very small example with a text that goes over 2 pages so that I can see what is really necessary for that? I already tested the example of MigraDoc but it stops debugging at different points. That's why I ask for a small example – Benziner Nov 23 '16 at 12:12