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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting custom page size in pdfdocument

Thread ID:

Created:

Updated:

Platform:

Replies:

130769 Jun 1,2017 09:14 AM UTC Jun 9,2017 10:45 AM UTC Xamarin.iOS 8
loading
Tags: PDF
Balasubramanian Ramanathan
Asked On June 1, 2017 09:14 AM UTC

Hi,

I am setting custom page size in pagesetting pdfdocument and using pdflighttable and sepcifying column width explicitly by calculating the width using pdffont.measurestring.

However in the exported pdf the page size seems to be the default size and column widths are proportnally reduced.

I am not sure how to solve this.

My Requirements.

I need to export table of data with 11 columns to pdf resulting total width of 1500 points, witth custom width for every pdfcolumn in pdflighttable. 

What is the best possible option to export the 11 columns to pdf
1) Setting the  page width to the total width. I tried this and it does not work
2) Is it possible to have first row with 5 columns and second row with 6 columns and limit the page size to A4. ie i want to span the columns to next row when the column position goes beyond the a4 size width. How do i achive this.

And alos it seems to all syncfusion xamarin nuget pacakegs are dependent on xamarin forms.  Assume that i am referencing the pdf/xlsio package in a .net standard library it is trying to install dependent xamarin forms and the package installation fails. Please remove xamarin.forms dependecny in syncfusion xamarin packages if we want to use them in pcl or standar libraries.

Thank You.

Balasubramanian Ramanathan
Replied On June 1, 2017 01:12 PM UTC

Hi,

When i set pdfDocument.PageSettings.Size = new SizeF(1500,800)   instead of 1500 as width, the height is set as 1500 and width is set as 800. I am not sure why it is being always reversed.

Please clarify.

Surya Kumar [Syncfusion]
Replied On June 2, 2017 02:29 PM UTC

Hi Balasubramanian, 
 
Thank you for using Syncfusion products. 
 
We have analysed the behaviour which you have mentioned in your query, please find the response for the same below: 
Query 
Response 
When i set pdfDocument.PageSettings.Size = new SizeF(1500,800)   instead of 1500 as width, the height is set as 1500 and width is set as 800. I am not sure why it is being always reversed. 
Since the default orientation of the PDF document will be “portrait” when the size to the document is given the higher value in size will be set as height and lower value will be set as width, this the natural behaviour in our library in order to achieve your requirement, the document orientation should be set as “landscape” refer the below code snippet: 
    PdfDocument doc = new PdfDocument(); 
 
            //Set Orientation and page Size 
 
   doc.PageSettings.Orientation = PdfPageOrientation.Landscape; 
 
       doc.PageSettings.Size = new SizeF(1500, 800); 
 
 
I need to export table of data with 11 columns to pdf resulting total width of 1500 points, witth custom width for every pdfcolumn in pdflighttable.  
We have created a work around code snippet for your requirement this can be found below this table 
 Is it possible to have first row with 5 columns and second row with 6 columns and limit the page size to A4. ie i want to span the columns to next row when the column position goes beyond the a4 size width. How do i achive this. 
 
PdflightTable do not have support for spanning the columns and drawing in the next line, but PdfGrid has the support to span the columns to the next page, the code snippet for this can be referred from the below KB link : 
 
 
 
Please find the code snippet to achieve the requirement which you mentioned: 
 
            //Create a new PDF document. 
 
            PdfDocument doc = new PdfDocument(); 
 
            //Set Orientation and page Size 
 
            doc.PageSettings.Orientation = PdfPageOrientation.Landscape; 
 
            doc.PageSettings.Size = new SizeF(1500, 800); 
 
 
            //Add a page. 
            PdfPage page = doc.Pages.Add(); 
 
 
 
            // Create a PdfLightTable. 
 
            PdfLightTable pdfLightTable = new PdfLightTable(); 
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); 
        pdfLightTable.Style.DefaultStyle = new PdfCellStyle(font, PdfBrushes.Black, PdfPens.Black); 
 
            //Assign data source. 
 
            pdfLightTable.DataSourceType = PdfLightTableDataSourceType.TableDirect; 
 
            //Include columns to the Table. 
            for (int i = 0; i < 11; i++) 
                pdfLightTable.Columns.Add(new PdfColumn("column" + i)); 
 
 
 
            //Include rows to the Table. 
            for (int i = 0; i < 5; i++) 
            { 
          pdfLightTable.Rows.Add(new string[] { "abc", "21", "row", "TestValue1", "TestValue2", "TestValue3", "TestValue4", "TestValue5", "TestValue6", "TestValue7", "TestValue8" }); 
          pdfLightTable.Rows.Add(new string[] { "abcabc", "21", "row-data", "TestValue1-Value", "TestValue2", "TestValue3-Value", "TestValue4", "TestValue5-Value", "TestValue6", "TestValue7", "TestValue8-Value" }); 
 
            } 
 
 
 
            float colWidth = 0; 
 
            //This loop will set the column width by measuring string values in the column 
 
            for (int col = 0; col < pdfLightTable.Columns.Count; col++) 
            { 
 
                for (int row = 0; row < pdfLightTable.Rows.Count; row++) 
                { 
                    string value = (pdfLightTable.Rows[row].Values[col]).ToString(); 
                    if (colWidth == 0 || colWidth < font.MeasureString(value).Width) 
                        colWidth = font.MeasureString(value).Width; 
                } 
                pdfLightTable.Columns[col].Width = colWidth; 
                colWidth = 0; 
 
            } 
 
 
            //Draw PdfLightTable. 
 
            pdfLightTable.Draw(page, new PointF(0, 0)); 
 
            MemoryStream ms = new MemoryStream(); 
 
            doc.Save(ms); 
 
            //Close the document 
 
            doc.Close(true); 



Query regarding Xamarin forms : 
And alos it seems to all syncfusion xamarin nuget pacakegs are dependent on xamarin forms.  Assume that i am referencing the pdf/xlsio package in a .net standard library it is trying to install dependent xamarin forms and the package installation fails. Please remove xamarin.forms dependecny in syncfusion xamarin packages if we want to use them in pcl or standar libraries. 

Response: 

Currently we are providing the Xamarin.Forms NuGet package as dependent package for our Syncfusion Xamarin NuGet packages. We cannot remove the Xamarin.Forms NuGet package from the Syncfusion Xamarin NuGet packages since it will be affected our controls in the Xamarin projects. If you need to use the Syncfusion Xamarin packages in .NET Standard library, we suggest you to choose the IgnoreDependencies option which is available in the NuGet Package Manager while installing the each Syncfusion Xamarin NuGet package to avoid the dependencies of the NuGet Package. Please refer the below screenshot for your reference.  
  
   
  
You can also use the below Package Manager console commands to ignore the dependencies while installing/updating the Syncfusion NuGet packages.   
  
Install command:  
PM> Install -Package <Package Name>  - IgnoreDependencies  
For example: PM> Install-Package Syncfusion.Xamarin.Pdf -IgnoreDependencies  
  
 
Update command:  
PM> Update-Package <Package Name>  - IgnoreDependencies  
For example: PM> Update -Package Syncfusion. Xamarin.Pdf -IgnoreDependencies . 
 
 
Please let us know if you need any further information in this. 
 
Regards, 
Surya Kumar 


Balasubramanian Ramanathan
Replied On June 2, 2017 08:59 PM UTC

Thank you very much for the detailed explanation. All my queries are resolved.


Balasubramanian Ramanathan
Replied On June 3, 2017 02:00 AM UTC

Regarding the nuget package how can i ignore dependencies in visual studio for max or xamarin studio

Thanks

Balasubramanian Ramanathan
Replied On June 3, 2017 02:23 AM UTC

Hi,

It seems to be the nuget pacakge is not compatible with .net standard 1.6. So i am not able to use the provided nuget packages.

Please add support for .net standard in nuget packages.

Thanks

Surya Kumar [Syncfusion]
Replied On June 7, 2017 10:37 AM UTC

Hi Balasubramanian, 
 
Please find the response for your last updated queries below: 
 
Query  
Response 
It seems to be the nuget pacakge is not compatible with .net standard 1.6. So i am not able to use the provided nuget packages. 
 
Please add support for .net standard in nuget packages. 
You may use “Syncfusion.Pdf.Portable” assembly if you need .Net Standard 1.6 compatible nugget packages. 
Which can be referenced from below link: 
 
 
Regarding the nuget package how can i ignore dependencies in visual studio for max or xamarin studio
 
For Xamarin Studio we should use the PowerShell commands to utilize the ignore dependencies option while installing the NuGet. Before that we need to update the Package manager extension. The details are explained clearly in below link, 
 
 
After installing the package manager extension, install the Syncfusion Xamarin NuGet packages by using below installation command with the IgnoreDependencies parameter. Please refer the below screenshot for your reference. 
 
PM> install-Package Syncfusion.Xamarin.Pdf -IgnoreDependencies 
 
 
 
 
 
Also Powershell command structures are explained in below link, 
 
 
For MAC we have updated the packages installation using console in detail in below UG link, 
 
 
 
 
 
Please let us know if you need any further assistance regarding this. 
 
Regards, 
Surya Kumar 


Balasubramanian Ramanathan
Replied On June 8, 2017 11:32 AM UTC

Thank You.

I am using the aspnet core nuget source. It solved my problem

Thank you

Surya Kumar [Syncfusion]
Replied On June 9, 2017 10:45 AM UTC

Hi Balasubramanian, 
 
Thanks for your update, let us know if you need any further assistance. 
 
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.

Warning Icon 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.Close Icon

;