This is a migrated thread and some comments may be shown as answers.

RadPdfProcessing content transition for a new page

1 Answer 375 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Michal
Top achievements
Rank 1
Michal asked on 10 Jun 2019, 12:55 PM

Hi all, 

I'm using RadPdfProcessing for ASP.NET MVC to create pdf template for financial documents. Sometimes content of some tables can be various length. In this case I'd like to move lower blocks/tables to a new page and generate pdf document with two pages. I'm using RadFixedDocument and FixedContentEditor to create tables/blocks on the document.  Piece of ode below:

  public static RadFixedDocument CreateDocument()
{
      RadFixedDocument document = new RadFixedDocument();
      RadFixedPage page = new RadFixedPage();          
       page.Size = new Size(600, 750);           
             
      FixedContentEditor editor = new FixedContentEditor(page);
      document.Pages.Add(page);
 
      editor.Position.Translate(defaultLeftIndent + 330, defaultTopIndent);
            DrawTable(editor, maxWidth);
 
            editor.Position.Translate(defaultLeftIndent, defaultTopIndent + 70);
            DrawTitle(editor, maxWidth);
 
            editor.Position.Translate(defaultLeftIndent, defaultTopIndent + 110);
            DrawTableWithDetails(editor, maxWidth);
            
            editor.Position.Translate(defaultLeftIndent, defaultTopIndent + 220);
            DrawReceiverTable(editor, maxWidth);
         
             private static void DrawTable(FixedContentEditor editor, double maxWidth)
        {
            Table table = new Table();
            table.LayoutType = TableLayoutType.AutoFit;
            table.DefaultCellProperties.Padding = new Thickness(1);
 
            #region FIRST ROW
            TableRow firstRow = table.Rows.AddTableRow();
            TableCell firstCell = firstRow.Cells.AddTableCell();
            Block firstBlock = firstCell.Blocks.AddBlock();
            firstBlock.TextProperties.FontSize = 10;
            firstBlock.TextProperties.Font = FontsRepository.Helvetica;
            firstBlock.InsertText("xxxxxxxxx");
 
            TableCell secondCell = firstRow.Cells.AddTableCell();
            Block secondBlock = secondCell.Blocks.AddBlock();
            secondBlock.TextProperties.FontSize = 10;
            secondBlock.TextProperties.Font = FontsRepository.Helvetica;
            secondBlock.InsertText(" xxxxxxxxx");
            #endregion
            editor.DrawTable(table, new Size(maxWidth, double.PositiveInfinity));
 
        }
 
        private static void DrawTitle(FixedContentEditor editor, double maxWidth)
        {
            Block block = new Block();
            block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.Font = FontsRepository.HelveticaBold;
            block.TextProperties.FontSize = 16;
            block.InsertText("xxxxxxxxx");
            block.InsertText("<xxxxxxxxx>");
            editor.DrawBlock(block, new Size(maxWidth, double.PositiveInfinity));
        }
 
        private static void DrawTableWithDetails(FixedContentEditor editor, double maxWidth)
        {
            Table table = new Table();
            table.LayoutType = TableLayoutType.FixedWidth;
            table.DefaultCellProperties.Padding = new Thickness(1);
            Border border = new Border();
            Border whiteBorder = new Border(0, BorderStyle.None, new RgbColor(255, 255, 255));
            table.DefaultCellProperties.Borders = new TableCellBorders(border, border, border, border);
            #region FIRST ROW
            TableRow firstRow = table.Rows.AddTableRow();
            TableCell firstCell = firstRow.Cells.AddTableCell();
            Block firstBlock = firstCell.Blocks.AddBlock();
            firstBlock.TextProperties.Font = FontsRepository.HelveticaBold;
            firstBlock.InsertText("xxxxxxxxx");
            TableCell secondCell = firstRow.Cells.AddTableCell();
            Block secondBlock = secondCell.Blocks.AddBlock();
            secondBlock.TextProperties.Font = FontsRepository.HelveticaBold;
            secondBlock.InsertText("xxxxxxxxx");
            #endregion
            #region SECOND ROW
            TableRow secondRow = table.Rows.AddTableRow();
            firstCell = secondRow.Cells.AddTableCell();
            firstCell.Borders = new TableCellBorders(border, border, border, whiteBorder);
            firstBlock = firstCell.Blocks.AddBlock();
            firstBlock.TextProperties.FontSize = 10;
            firstBlock.InsertText("xxxxxxxxx");
            secondCell = secondRow.Cells.AddTableCell();
            secondCell.Borders = new TableCellBorders(border, border, border, whiteBorder);
            secondBlock = secondCell.Blocks.AddBlock();
            secondBlock.TextProperties.FontSize = 10;
            secondBlock.InsertText("xxxxxxxxx");
            #endregion
            editor.DrawTable(table, new Size(maxWidth, double.PositiveInfinity));
        }
 
        private static void DrawReceiverTable(FixedContentEditor editor, double maxWidth)
        {
            Table table = new Table();
            table.LayoutType = TableLayoutType.FixedWidth;
            table.DefaultCellProperties.Padding = new Thickness(1);
            Border border = new Border();
            Border whiteBorder = new Border(0, BorderStyle.None, new RgbColor(255, 255, 255));
            table.DefaultCellProperties.Borders = new TableCellBorders(border, border, border, border);
            #region TABLE CONTENT
            TableRow firstRow = table.Rows.AddTableRow();
            TableCell firstCell = firstRow.Cells.AddTableCell();
            Block firstBlock = firstCell.Blocks.AddBlock();
            firstBlock.TextProperties.Font = FontsRepository.HelveticaBold;
            firstBlock.InsertText("xxxxxxxxx");
 
            TableRow secondRow = table.Rows.AddTableRow();
            firstCell = secondRow.Cells.AddTableCell();
            firstCell.Borders = new TableCellBorders(border, border, border, whiteBorder);
            firstBlock = firstCell.Blocks.AddBlock();
            firstBlock.TextProperties.FontSize = 10;
            firstBlock.InsertText("xxxxxxxxx");
            #endregion
            editor.DrawBlock(table, new Size(maxWidth, double.PositiveInfinity));
        }
}

1 Answer, 1 is accepted

Sort by
0
Nikolay Demirev
Telerik team
answered on 13 Jun 2019, 08:47 AM
Hello Michal,

Have you tried measuring and spiting the block like described in this article https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/block#measuring-block-size? This way you will be able to split the block and arrange them one after another. Knowing the page size from its properties, you would be able calculate if there is enough space left on the page and split content if you need to place it into another page.

Easier option is to use the RadFixedDocumentEditor which helps generate documents which content flows to pages. You can insert Paragraphs, Tables, Blocks and when the page is filled a new page will be created. Here you can read more about the RadFixedDocumentEditor https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/editing/radfixeddocumenteditor.

Another option is to use the RadWordsProcessing to layout the content of the pages and then export your document to PDF format. This way the RadWordsProcessing will do the heavy lifting of splitting pages and arranging the content. Here you can find more information about the RadWordsProcessing library https://docs.telerik.com/devtools/document-processing/libraries/radwordsprocessing/overview.

I hope I was able to help you.

Regards,
Nikolay Demirev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfProcessing
Asked by
Michal
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Share this question
or