|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, I wanted to know if the following can be achieved with table object in PDF Creator.
1. When table is large and split to 2 pages, the header names should appear on the second page also.
2. but information in particular Row is not split on two pages. (Row is always kept together)
3. When we have a Report with lot of dynamic tables, is there a way the whole table goes to a new page if there is space only for the headers and the data goes to the next page.
4. Any property for Table object like "Table fits page"
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You will need to use the HTML to PDF to do that. PDF Creator can't do "not split" and repeating headers.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, Thanks for your reply.
1. I am using PDF Creator to generate PDF and wanted to know if 'HTML to PDF' can be used with PDF Creator. 2. If yes, could you please post a sample code for creating "repeating headers" and "not split table rows". 3. Else, is it possible to create the PDF using PDF Creator but tables using 'HTML to PDF' and merge the generated PDFs.
Plz let me know if you have any other suggestions to achieve the below mentioned functionality with PDF Creator.
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Yes. You can use both together. For example, you can use HTML to PDF to generate the first half of the page and use PDF Creator to generate the second half of the page, or to use HTML to PDF to generate the main contents and then use PDF Creator to generate an overlay rubberstamp on top of the main content. The key is both HTML to PDF and PDF Creator output to a PdfDocument and ultimately to PdfPage object. So pretty much all you do is to use the same PdfDocument/PdfPage object when calling them. You DO NOT have to create separate PDF files and then merge them. You can find sample code in “All Demos -> HTML to PDF -> Advanced -> Using with PDF Creator” sample in the sample project. Repeating table headers and footers: http://doc.essentialobjects.com/library/4/htmltopdf/table_header.aspxKeeping table row together (use “page-break-inside:avoid” on your table row): http://doc.essentialobjects.com/library/4/htmltopdf/paging.aspxThe current build on our download page has a few problems with table headers and footers. We already have a newer build that fixed those problems. We will PM you with the download location for that build. Make sure you use the new build if you want to try out the table header/footer feature. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, I have tried implementing both HTMLToPDF and PDF Creator using same PdfDocument as suggested but the content was overlaping one another. The tables are dynamic and hence I cannot use AcmPageLayout to define the start position for PDF Creator.
How can I create PdfDocument both with HTMLToPDF and PDF Creator without overlapping of content ? My Code is as below:
Sample Code: PdfDocument doc = new PdfDocument();
StringBuilder sb = new StringBuilder(); sb.AppendLine("<table style='width:600px'>"); sb.AppendLine("<thead><td>"); sb.AppendLine("<div style='border-bottom:solid 1px black;font-weight:bold;'>Table Header</div>"); sb.AppendLine("</td></thead>");
for (int i = 0; i < 100; i++) { sb.Append("<tr><td>"); sb.AppendFormat("Table Item {0}", i + 1); sb.AppendLine("</td></tr>"); } sb.AppendLine("</table>");
//Convert the Url to PDF HtmlToPdf.ConvertHtml(sb.ToString(), doc); //Create a new render using the same document object AcmRender render = new AcmRender(doc); //This is the root content AcmContent root = new AcmContent(); AcmText header = new AcmText("This content is from PDF Creator."); root.Children.Add(header); render.Render(root); doc.Save(strFileName);
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, The ConvertHtml function returns an HtmlToPdfResult object. From that result object you can get the last page index and last page position:
Code: C#
//The returned HtmlToPdfResult object contains a lot of information
//about the HTML page
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(sb.ToString(), doc);
//Get the last page index and last page position
int lastPageIndex = result.LastPageIndex;
int lastPosition = result.LastPosition;
For example, if your table is one and a half page, then lastPageIndex will be 1 (second page, zero based) and lastPosition will be 4.5 (in inches, at the middle of the page). You can then uses these two values to set the start position of your AcmRender object:
Code: C#
AcmRender render = new AcmRender(
//Start from the page specified by lastPageIndex
doc.Pages[lastPageIndex],
//Start from lastPosition on that page
lastPosition);
This way AcmRender will output exactly after the HTML to PDF's output. Hope this helps. Let us know if you still have more questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, Thanks for your quick reply !! I have tried your suggestion and it worked.
But could not achieve the below 1. If I want to append HTMLtoPDF after PDFCreator output, how do I get the last page index and last page position similar to HtmlToPdfResult . 2. Also I am using Watermark and it works fine for PDF sections created from PDFCreator but not for sections from HTMLtoPDF. HTMLtoPDF does not seem to be rendered if Watermark is used. 3. If there is space only for the headers, is there a way to output table on new page instead of splitting header and table data.
Thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, As to your questions: 1. In order to get the page index and position of PdfCreator output, you will need to place a dummy AcmContent object (for example, a blank AcmText object) at the end of your ACM object tree, then call the following code to get a PdfDestination object of that content object after you have already called AcmRender.Render:
Code: C#
//Create a PdfDestination object that points to the position
//of the ACM object
PdfDestination dest = dummyText.CreateDestination();
You can then use dest.Page and dest.FitRect.Y1 to get the pdf page and page position respectively. In order to pass this value to Html To PDF converter, you would set HtmlToPdf.Options.StartPageIndex and HtmlToPdf.Options.StartPosition. 2. You can not use watermark on HTML to PDF output. HTML to PDF output always starts with a solid white background, that will completely obscure your watermark. You can only generate additional output on top of the HTML to PDF output, not below it; 3. You will need to use HTML to PDF repeating table header feature for that. Neither regular HTML table nor ACM table will automatically avoid empty table headers. However as soon as you explicitly mark it as a table header group, the auto repeating feature will kick in and prevent empty headers; Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, I tried to use PdfDestination object as per suggestion 1, but somehow it did not work. Please refer to sample code below. Sample Code:
Code: C#
//Create a new PdfDocument
PdfDocument doc = new PdfDocument();
//Create a new render
AcmRender render1 = new AcmRender(doc);
AcmContent root1 = new AcmContent();
AcmText header = new AcmText("This content is from PDF Creator.");
root1.Children.Add(header);
AcmText text = new AcmText("Dummy Text");
render1.Render(root1, text);
PdfDestination dest = text.CreateDestination();
StringBuilder sb = new StringBuilder();
sb.AppendLine("<table style='width:600px'>");
sb.AppendLine("<thead><td>");
sb.AppendLine("<div style='border-bottom:solid 1px black;font-weight:bold;'>Table Header</div>");
sb.AppendLine("</td></thead>");
for (int i = 0; i < 20; i++)
{
sb.Append("<tr><td>");
sb.AppendFormat("Table Item {0}", i + 1);
sb.AppendLine("</td></tr>");
}
sb.AppendLine("</table>");
//Convert the HTML to PDF
HtmlToPdf.Options.StartPageIndex = dest.Page.Index;
HtmlToPdf.Options.StartPosition = dest.FitRect.Y1;
EO.Pdf.HtmlToPdf.Options.AfterRenderPage = new EO.Pdf.PdfPageEventHandler(On_AfterRenderPage);
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(sb.ToString(), doc);
Thanks once again.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, There are two problems: 1. PdfDestionation.FitRect.Y1 is in user space coordinate (not in inch, and goes from bottom to top instead of from top to bottom). See here for more details about PDF user space coordination: http://doc.essentialobjects.com/library/4/acm/pdf%20content%20api/content_api_basic.aspx2. You would usually use a block element instead of an inline element to measure the bottom of your output. In your case, if all coordinate from top to bottom, then the Y1 value for "This content is from PDF Creator." and "Dummy Text" would be 0 because they would appear in the same line, this defeats the purpose of having an additional element completely since "Dummy text" does not give you the point below "this content is from PDF creator". Try use a AcmBlock around the AcmText will solve that problem; Hope this helps. Let us know if you still have questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, It would be helpful if you could provide some sample code on how to use PdfDestionation.FitRect.Y1 in order to render HTMLtoPdf after PDFCreator object. If the below code does not work, how do you use PdfDestionation object
Code: C#
//Convert the HTML to PDF
HtmlToPdf.Options.StartPageIndex = PdfDestionation.Page.Index;
HtmlToPdf.Options.StartPosition = PdfDestionation.FitRect.Y1;
Thanks !!!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You do something like this:
HtmlToPdf.Options.StartPosition = (float)(10 * 72 - PdfDestionation.FitRect.Y1) / 72;
The key is Y1 is in point, not inch. StartPosition is in inch, so you have to devide Y1 by 72 to get the inch value; Also the zero point of Y1 is at the bottom of the paper, where the zero point of StartPosition is at the top of the page.
If you still have problems, check the value of Y1 in debugger and adjust the formula accordingly.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 9/23/2011 Posts: 8
|
Hi, 1. I have tried your suggestion, and could render the HTMLtoPDF content after PDFCreator object with dynamic positioning. But I have ran into issues when I try to define layout for HTMLtoPdf content. How do you define page layout for HTMLtoPDF to be same as my PDFCreator. Please verify my sample code and let me know if I am missing anything. 2. Also the PDFCreator is enclosed in a block which has border defined, how can I define border for HTMLtoPdf Content also. 3. I am using PDFCreator and liked flexibility and features that it supports. But incorporating HTMLtoPdf into PDFCreator for getting its table features has complicated the solution. I would like to know if there is any scope for incorporating HTMLtoPdf table features into PDFCreator, which would help us in finalizing PDF product for our application.
Code: C#
//Append HTML to PDF to PDF Creator
HtmlToPdf.Options.StartPageIndex = dest.Page.Index;
HtmlToPdf.Options.StartPosition = (float)(10 * 72 - dest.FitRect.Y1) / 72;
HtmlToPdf.Options.OutputArea = new RectangleF(0.4f, 0.7f, doc.Pages[0].Size.Width - 1f, doc.Pages[0].Size.Height-1.5f);
HtmlToPdfResult result = HtmlToPdf.ConvertHtml(sb.ToString(), doc);
//Get the last page index and last page position
lastPageIndex = result.LastPageIndex;
lastPosition = result.LastPosition;
// Append PDFCreator to HTMLtoPdf
render = new AcmRender(doc.Pages[lastPageIndex], lastPosition + 0.3f, new AcmPageLayout(new AcmPadding(0.4f, 0.7f, 0.4f, 1f))); //
//This is the root content
root = new AcmContent();
//PLOP - Assessments
blockPLOP = new AcmBlock();
blockPLOP.Style.Border = new AcmBorder(new AcmLineInfo(0.01f), null, new AcmLineInfo(0.01f), new AcmLineInfo(0.01f));
blockPLOP.Children.Add(new AcmParagraph());
AcmText txtAreas = new AcmText("Results of initial or most recent evaluation:");
blockPLOP.Children.Add(txtAreas);
Thanks once again.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
As to your question:
1. Usually you don't need to worry about the page layout at all. Both HTML to PDF's and PDF Creator's page layout points to the full page. The only difference is their start position. When you need one to follow another, you set one's start position as the other's end position and that's it. You don't have to adjust page layout for either one.
2. For anything about HTML to PDF output, you do it on your input HTML, period. If you have a border on your HTML, it shows up with border. If you do not have a border on your HTML, it doesn't show a border. It has nothing to do with anything else;
3. Why not use HTML to PDF for everything? It will be much easier and less code for you. HTML to PDF provides far more feature and options than PDF Creator. PDF Creator is faster but it is usually only good for small document because you need to create pretty much with code. HTML to PDF on the other hand can handle pretty anything you can display in your browser. The best scenario to mix up the two is to use HTML to PDF to render the main contents and then use PDF Creator to render some "add ons" (such as header and footer). If you intend to use it any other way, it will definitely save you time by using HTML to PDF for all contents.
Hope this helps. Let us know if you still have any questions.
Thanks!
|
|