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

How to Export multiple pages using rad pdfprocessing

1 Answer 443 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
murali
Top achievements
Rank 1
murali asked on 28 Oct 2018, 01:00 PM

Hi Team,

I am using asp.net webforms.

I want to generate pdf from scratch.

pdf pages size should be A4.

and based on content length i need to generate multiple pages in the PDF.

I am using below code.

protected void btn2_Click(object sender, EventArgs e)
    {
List<string> contents = new List<string>();
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely" +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a document processing library that enables your application to " +
                         "import and export files to and from PDF format. " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("is a application to " +
                         "import and export files to and from PDF format. The document model is " +
                         "entirely independent from UI and allows " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is111 " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is222 " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
        contents.Add("The document model is " +
                         "entirely independent from UI and allows you to generate sleek documents " +
                         "with differently formatted text, images, shapes and more.");
 
var document = new RadFixedDocument();
        var page = document.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(page);
 var x = 50;
        var y = 50;
 
        foreach (var item in contents)
        {
            editor.Position.Translate(x, y); //Start Position(x,y)
            Block block = new Block();
            block.GraphicProperties.FillColor = RgbColors.Black;
            block.HorizontalAlignment = HorizontalAlignment.Left;
            block.TextProperties.Font = FontsRepository.HelveticaBoldOblique;
            block.TextProperties.FontSize = 20;
            block.InsertText("RadPdfProcessing");
 
            block.TextProperties.Font = FontsRepository.Helvetica;
            block.TextProperties.FontSize = 20;
            block.InsertText(item);
            editor.DrawBlock(block, new System.Windows.Size(700, double.PositiveInfinity));
            //x = x + 50;
           // y = y + 150;
        }
 
 
        var pdfProvider = new PdfFormatProvider();
        byte[] renderedBytes = null;
        using (MemoryStream ms = new MemoryStream())
        {
            pdfProvider.Export(document, ms);
            renderedBytes = ms.ToArray();
        }
        Response.Clear();
        Response.AppendHeader("Content-Disposition:", "attachment; filename=PdfDocument.pdf");
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(renderedBytes);
        Response.End();
    }

but the above code generating only single page.

how can i generate multiple pages based on content. and provide me any examples.

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 31 Oct 2018, 04:07 PM
Hello Murali,

PDF documents consist of instructions for drawing, so we've exposed similar functionality in the API of RadPdfProcessing as well. The FixedContentEditor class you're using is intended to facilitate the creation of a page in a document and it allows drawing different types of elements, positioning them on the page, etc. To achieve the desired behavior using this editor you will need to implement some extra logic for separating the content. You can separate the text that doesn’t fit using the Block class, more specifically, its hasPendingContent property and the Split() method. You can find an example demonstrating a pretty similar case in our public forums: https://www.telerik.com/forums/repeat-table-heading-after-page-break#kH616fyAKUiDl6WAknUILg.

If you'd like to create a fixed document that will automatically "flow" to pages similar to how a word editor behaves when adding content, consider adopting the RadFixedDocumentEditor class instead. You can take a look at our CreatePdfUsingRadFixedDocumentEditor SDK example for a reference.

Regards,
Martin
Progress Telerik

Tags
PdfProcessing
Asked by
murali
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or