We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Add text on PDF converted from Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

130086 Apr 20,2017 11:14 AM Apr 21,2017 03:28 AM ASP.NET MVC 1
loading
Tags: PDF
Nicola
Asked On April 20, 2017 11:14 AM

Hi , i want to add some text in PDF page but my PDF is a result from ExcelToPdfConverter.

I tried this:
                //Open the Excel Sheet to Convert                 ExcelToPdfConverter converter = new ExcelToPdfConverter(wSheet);
                //Intialize PDF Document                 PdfDocument pdfDocument = new PdfDocument();
                //Add page                  pdfDocument.Pages.Add();                     //                 RectangleF rect = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50);                 //Create page template                 PdfPageTemplateElement header = new PdfPageTemplateElement(rect);                 Color activeColor = Color.FromArgb(44, 71, 120);                 PdfSolidBrush brush = new PdfSolidBrush(activeColor);                 PdfPen pen = new PdfPen(Color.DarkBlue, 3f);                 PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);                 //Set formattings for the text                 PdfStringFormat format = new PdfStringFormat();                 format.Alignment = PdfTextAlignment.Center;                 format.LineAlignment = PdfVerticalAlignment.Middle;                 //Draw title                 header.Graphics.DrawString("TITLE", font, brush, new RectangleF(0, 0, header.Width, header.Height), format);                                  pdfDocument.Template.Top = header;                                  //Initialize converter settings                 ExcelToPdfConverterSettings cs= new ExcelToPdfConverterSettings();                 cs.TemplateDocument = pdfDocument;                 //Convert Excel Document into PDF document                 pdfDocument = converter.Convert(cs);

With this code, I obtain a PDF with 2 pages. The first is a blank page with header "TITLE", the second is a page with header "TITLE" and the excel sheet converted .

How to remove the first page ? And , this is a right way to achieve my target?



Surya Kumar [Syncfusion]
Replied On April 21, 2017 03:28 AM

Hi Nicola, 
 
Thank you for using Syncfusion Products. 
 
In the code snippet, which you have posted in the last update has the code to add new page to the created PDF document before assigning the converted Excel to PDF file as shown below: 
 
This the reason for the addition of the extra page in the beginning of the document. 
 
This can be avoided by adding the new page and setting the width of the header manually, in order to set the default width of the page as header width, please refer the below code snippet: 
 
            //Setting the header bounds 
            RectangleF rect = new RectangleF(0, 0, 515, 50); 
 
            //Create page template 
            PdfPageTemplateElement header = new PdfPageTemplateElement(rect); 

 
Please find the width details of a A4 page: 
Default width: 595. 
Default margin value for left and right: 40 
Width of the page after applying left and right margins:  595-40-40= 515. 
 
We have attached a sample with the made changes, please find it from the below link: 
 
 
Let us know if you need any further assistance regarding this. 
 
Regards, 
Surya Kumar 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;