Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sat Jul 07, 2018 8:31 am

Code: Select all
                // Get reference to cell that will hold company information.
                PdfGridCell infoCell = companyRow.Cells[1];

                // Set font style.
                infoCell.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);

                // Set spacing between the lines of text.
                infoCell.Style.StringFormat = new PdfStringFormat
                {
                    LineSpacing = infoCell.Style.Font.Size * 2f
                };

                // Create collection that will hold all cell assets.
                PdfGridCellTextAndStyleList infoCellTextAndStyleList = new PdfGridCellTextAndStyleList();

                // Break company information text to multiple lines.
                string[] infoTextLines = company.Information.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string infoTextLine in infoTextLines)
                {
                    // Create one asset.
                    PdfGridCellTextAndStyle infoCellTextAndStyle = new PdfGridCellTextAndStyle
                    {
                        Font = new PdfTrueTypeFont(new Font("Arial", 10f), true),
                        Text = $"\n{infoTextLine}"
                    };

                    // Add asset to collection.
                    infoCellTextAndStyleList.List.Add(infoCellTextAndStyle);
                }

                // Assign asset collection to cell.
                infoCell.Value = infoCellTextAndStyleList;


This is the code snippet we are using to draw multiline text in a single cell.
We have set LineSpacing property on PdfStringFormat, however text lines continue to be without spacing.

Are we missing something?

admir.tuzovic
 
Posts: 2
Joined: Sat Jul 07, 2018 8:18 am

Mon Jul 09, 2018 4:39 am

Hello,

Thank you for your post.
For your case, there are two points I'd like to mention.
1. We have made some modifications to the name of "PdfGridCellTextAndStyleList" and "PdfGridCellTextAndStyle" from version 4.5.8. The "PdfGridCellTextAndStyleList" has been changed to "PdfGridCellContentList".and the "PdfGridCellTextAndStyle" has been changed to "PdfGridCellContent".
2. When setting the line space for all the cell content, you need to assign the "StringFormat" property in "PdfGridCellContent" object rather than the GridCell object.
Please download the latest Spire.PDF Pack(Hot Fix) Version:4.6.8 and use the following code to accomplish your task.
Code: Select all
// Get reference to cell that will hold company information.
PdfGridCell infoCell = companyRow.Cells[1];

// Set font style.
infoCell.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);

//// Set spacing between the lines of text.
//infoCell.Style.StringFormat = new PdfStringFormat
//{
//    LineSpacing = infoCell.Style.Font.Size * 2f
//};

StringFormat sf= new PdfStringFormat
{
    LineSpacing = infoCell.Style.Font.Size * 2f
};
// Create collection that will hold all cell assets.
PdfGridCellContentList infoCellTextAndStyleList = new PdfGridCellContentList();

// Break company information text to multiple lines.
string[] infoTextLines = company.Information.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

foreach (string infoTextLine in infoTextLines)
{
    // Create one asset.
    PdfGridCellContent  infoCellTextAndStyle = new PdfGridCellContent
    {
        Font = new PdfTrueTypeFont(new Font("Arial", 10f), true),
        Text = $"\n{infoTextLine}",
        StringFormat = sf //Jane added_ setting the line space for each line
    };

    // Add asset to collection.
    infoCellTextAndStyleList.List.Add(infoCellTextAndStyle);
}

// Assign asset collection to cell.
infoCell.Value = infoCellTextAndStyleList;

    // Add asset to collection.
    infoCellTextAndStyleList.List.Add(infoCellTextAndStyle);
}

If there's still any doubt, just come back and share the entire code as well as the pdf docuemnt.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Jul 12, 2018 2:41 am

Hi admir.tuzovic,

Greetings from e-iceblue!
I wonder if your issue has been resolved. Your feedback would be greatly appreciated.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Jul 12, 2018 4:47 am

Hello!

I am so sorry - I wrote a response earlier this week but it didn't get saved. Probably because I have pasted link to NuGet.

Unfortunately, we haven't been able to test your solution since we are now using free version of your product.

Considering that we are happy with how your product works, we will most likely purchase OEM version soon once we are done with full evaluation.

In the meantime, do you know if free version will receive an update too?

Thank you!

admir.tuzovic
 
Posts: 2
Joined: Sat Jul 07, 2018 8:18 am

Thu Jul 12, 2018 6:26 am

Hi,

I'm sorry to tell that we don't update the free version. To help you better evaluate our commercial Spire.PDF, we could provide a one-month free license. If you are interested in it, just tell me or contact our sales team(sales@e-iceblue.com).

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF