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.

Thu Nov 23, 2017 5:24 pm

Hello,

I have done generating PDF file from c# MVC. Where I'm using HTML data string to generate pdf. In which Table can have n number of rows and i can't predict the exact height of each row because its all depeneds on the data entered by the user. I tried to restrict 5 rows in a page. but its does not looks good, whole page looks blank when user enters single line text for each row. i tried without restricting the rows per page, but it generating only one page and that too without full data, remaining data disappeared.

I have attached the samples, PFA

Is their any solution which automatically adjust the number of rows based on the data.

Thanks in advance.

aquib.raitech
 
Posts: 2
Joined: Thu Nov 23, 2017 4:48 pm

Fri Nov 24, 2017 2:24 am

Hello,

Thanks for your inquiry.
When you convert html to pdf, you could set the property "AutoDetectPageBreak" to be true like below so that the content will be automatically paginated.
Code: Select all
doc.LoadFromHTML(url, false, true, true);

If there's still any issue, please share your sample html and code so that we could look into it and provide a solution.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Fri Nov 24, 2017 10:27 am

Hello Jane,

Thanks for your reply. Now its breaking the page automatically. But header is not appearing in all the pages and some table rows are hiding due to top and bottom margin. In earlier enquiry i attached samples which have candidate details in every pages. Those details is coming from html string. But Now when i tried to add those html string to header. Its taking as normal string not as a html string.

I tried this code :
PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSetting.Width, margin.Top);

topSpace.Foreground = true;

PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Trebuchet MS", 12f, FontStyle.Italic));
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);

SizeF size = font1.MeasureString(pdfHeader, format);
float y = 0;
float x = PdfPageSize.A4.Width;
topSpace.Graphics.DrawString(pdfHeader, font1, PdfBrushes.PaleVioletRed, x, y, format);

pdf.Template.Top = topSpace;

-----------------------------
Where, pdfHeader is a htnl string (For ex: string pdfHeader = "<table><tr><td><label>Name</label></td><td>Candidate One</td></tr></table>"; )

aquib.raitech
 
Posts: 2
Joined: Thu Nov 23, 2017 4:48 pm

Mon Nov 27, 2017 6:27 am

Hello,

Thanks for your response.
Kindly note that the "DrawString" method should only be available for the drawing of strings, including the parsing of some text style tags if you turn the property "htmlTags" on. Accordingly to your description, you want to insert a table directly from a series of html string. Sorry our Spire.PDF does not support that at present. We will consider adding the feature to our future upgrade. Once there's any good news, I will let you know.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron