Weird errors when adding more content (like tablecells)
I’m
currently testing your awesome PDF Creator (locally) for a client project, and
looking forward to purchase, if I can get it working. The idea is to place some
.svg images and add measuring lines by generating tables with borders. I got it
working, but at some point I can’t add more tables or tablecells without
getting different errors. I believe the errors I’m getting is related to http://our.umbraco.org/projects/website-utilities/pdf-creator/bug-reports/26259-Unexpected-end-of-file-while-parsing-Name-has-occurred, like Tom expirences when adding more content, but as the Darren writes in the
last post this bug should be fixed in latest release.
I’m using a clean install of umbraco 4.9 and PDF Creator 2.1, and the generated xml seems fine and valid. You can download a
simplified razor Master in which the errors can be reproduced (at least on my
machine =) here: http://horsted.dk/pdftest.zip or see it at the end of the post...
The Master
as it is works, but when changing the ‘i < 12’ in line 34 to
add more tablecells like: @for(var i = 0; i <
13; i++)it generates the
following error: There is an unclosed literal
string. Line 157, position 43.
When
increasing to 14 like: @for(var i = 0; i <
14; i++)it generates
another error: Unexpected end of file has occurred.
The following elements are not closed: fo:table-cell, fo:table-row,
fo:table-body, fo:table, fo:flow, fo:page-sequence, fo:root. Line 292, position
6.
When
changing to: @for(var i = 0; i < 15; i++)it generates a similar (but different)
error: Unexpected end of file has occurred. The
following elements are not closed: fo:block, fo:table-cell, fo:table-row,
fo:table-body, fo:table, fo:flow, fo:page-sequence, fo:root. Line 289, position
20.
When
increasing to 17 like: @for(var i = 0; i <
17; i++)it (again)
generates the first error: Unexpected end of file
while parsing Name has occurred. Line 284, position 34.
By changing
the ‘j < values’ in the other cell-generating loops you can reproduce the
same errors as above. I mostly a frontend developer, and find this behavior
really weird and have no clue what’s going on. I really hope you can help me
out, as my client expects a prototype on their visit this Thursday morning :-/
If you need more info or anything else just let me know… Hope to hear from you
soon (also if you can’t fix, as it's just not possible to add more content). Thanks in advance and have a nice day :-)
I'am also testing the plugin locally. In my code, I counted the number of lines to be parsed (content from richtext-editor, textstring and so on) to about 100 in <fo:region-body> - if I add another line, it will crash ...
My code:
<%@ Master Language="C#" MasterPageFile="~/masterpages/PDFMaster.master" AutoEventWireup="true" %> <asp:content ContentPlaceHolderId="PdfContentPlaceHolder" runat="server"> <umbraco:Macro runat="server" language="cshtml"> @inherits umbraco.MacroEngines.DynamicNodeContext @using FergusonMoriyama.Pdf @using System.Xml @using umbraco.IO @{ Response.ContentType = "text/xml"; Response.AppendHeader("X-Pdf-Render","true"); // -- Uncomment this to force the browser to download the PDF. // Response.AppendHeader("X-Pdf-Force-Download","cv.pdf"); } <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ibex="http://www.xmlpdf.com/2003/ibex/Format"> <!-- Sets standard PDF Metadata --> <ibex:properties title="@Model.pdfName" author="@Model.WriterName" subject="" keywords="metat,bacon,sheep" creator="PDF Creator for Umbraco" />
<!-- Uncomment below to add protection to the PDF - optionally specify a password --> <!-- <ibex:security deny-print="true" deny-extract="true" deny-modify="true" user-password="" owner-password=""/> -->
<!-- This defines a simple page layout with a heder and a footer --> <!-- See http://www.w3schools.com/xslfo/obj_layout-master-set.asp --> <fo:layout-master-set> <fo:simple-page-master master-name="master" page-width="210mm" page-height="297mm" margin-top="2cm" margin-bottom="0cm" margin-left="2cm" margin-right="2cm"> <fo:region-body margin-top="0cm" margin-bottom="2.5cm" column-count="2" column-gap="1cm" color="#6b6b6b"/> <fo:region-before region-name="header" extent="0cm" margin-bottom="0cm" color="#ffffff" /> <fo:region-after region-name="footer" extent="2cm"/> </fo:simple-page-master> </fo:layout-master-set> <!-- Main content starts within page sequence --> <fo:page-sequence master-reference="master"> <!-- Document header --> <fo:flow flow-name="header"> </fo:flow>
Weird errors when adding more content (like tablecells)
I’m currently testing your awesome PDF Creator (locally) for a client project, and looking forward to purchase, if I can get it working. The idea is to place some .svg images and add measuring lines by generating tables with borders. I got it working, but at some point I can’t add more tables or tablecells without getting different errors. I believe the errors I’m getting is related to http://our.umbraco.org/projects/website-utilities/pdf-creator/bug-reports/26259-Unexpected-end-of-file-while-parsing-Name-has-occurred, like Tom expirences when adding more content, but as the Darren writes in the last post this bug should be fixed in latest release.
I’m using a clean install of umbraco 4.9 and PDF Creator 2.1, and the generated xml seems fine and valid. You can download a simplified razor Master in which the errors can be reproduced (at least on my machine =) here: http://horsted.dk/pdftest.zip or see it at the end of the post...
The Master as it is works, but when changing the ‘i < 12’ in line 34 to add more tablecells like: @for(var i = 0; i < 13; i++) it generates the following error: There is an unclosed literal string. Line 157, position 43.
When increasing to 14 like: @for(var i = 0; i < 14; i++) it generates another error: Unexpected end of file has occurred. The following elements are not closed: fo:table-cell, fo:table-row, fo:table-body, fo:table, fo:flow, fo:page-sequence, fo:root. Line 292, position 6.
When changing to: @for(var i = 0; i < 15; i++) it generates a similar (but different) error: Unexpected end of file has occurred. The following elements are not closed: fo:block, fo:table-cell, fo:table-row, fo:table-body, fo:table, fo:flow, fo:page-sequence, fo:root. Line 289, position 20.
When increasing to 17 like: @for(var i = 0; i < 17; i++) it (again) generates the first error: Unexpected end of file while parsing Name has occurred. Line 284, position 34.
By changing the ‘j < values’ in the other cell-generating loops you can reproduce the same errors as above. I mostly a frontend developer, and find this behavior really weird and have no clue what’s going on. I really hope you can help me out, as my client expects a prototype on their visit this Thursday morning :-/
If you need more info or anything else just let me know… Hope to hear from you soon (also if you can’t fix, as it's just not possible to add more content). Thanks in advance and have a nice day :-)
Cheers, Casper
<%@ Master Language="C#" MasterPageFile="~/masterpages/PDFMaster.master" AutoEventWireup="true" %> <asp:content ContentPlaceHolderId="PdfContentPlaceHolder" runat="server"> <umbraco:Macro runat="server" language="cshtml"> @inherits umbraco.MacroEngines.DynamicNodeContext @{ Response.ContentType = "text/xml"; Response.AppendHeader("X-Pdf-Render","true"); // -- Uncomment this to force the browser to download the PDF. // Response.AppendHeader("X-Pdf-Force-Download","darren.pdf"); } <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="A4" page-width="297mm" page-height="210mm" margin-top="1cm" margin-bottom="1cm" margin-left="1cm" margin-right="1cm"> <fo:region-body margin="3cm"/> <fo:region-before extent="2cm"/> <fo:region-after extent="2cm"/> <fo:region-start extent="2cm"/> <fo:region-end extent="2cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="A4"> <fo:flow flow-name="xsl-region-body"> <fo:table background-color="#ffffff" font-size=".5em" width="20cm" height="0.1cm"> <fo:table-body> <fo:table-row> <fo:table-cell border-width="0.02mm" border-bottom-style="solid" border-left-style="solid" border-right-style="solid"></fo:table-cell> @for(var i = 0; i < 12; i++) { <fo:table-cell border-width="0.02mm" border-right-style="solid" border-bottom-style="solid" ></fo:table-cell> } </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#ffffff" font-size=".5em" width="20cm" height="0.1cm"> <fo:table-body> <fo:table-row> <fo:table-cell border-width="0.02mm" border-left-style="solid" border-right-style="solid" border-top-style="solid"></fo:table-cell> @for(var j = 0; j < 12; j++) { <fo:table-cell border-width="0.02mm" border-right-style="solid" border-top-style="solid"></fo:table-cell> } </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#ffffff" font-size=".5em" width="20cm"> <fo:table-body> <fo:table-row> <fo:table-cell></fo:table-cell> <fo:table-cell text-align="center" border-width="0.02mm" background-color="#ffffff" position="relative" top="-2.2mm"> <fo:block>2400</fo:block> </fo:table-cell> <fo:table-cell></fo:table-cell> @for(var j = 0; j < 12; j++) { <fo:table-cell></fo:table-cell> <fo:table-cell text-align="center" border-width="0.02mm" background-color="#ffffff" position="relative" top="-2.2mm"> <fo:block>2400</fo:block> </fo:table-cell> <fo:table-cell></fo:table-cell> } </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#ffffff" font-size=".5em" width="20cm"> <fo:table-body> <fo:table-row height="0.1cm"> <fo:table-cell border-width="0.02mm" border-bottom-style="solid" border-left-style="solid" border-right-style="solid"> </fo:table-cell> </fo:table-row> <fo:table-row height="0.1cm"> <fo:table-cell border-width="0.02mm" border-left-style="solid" border-right-style="solid"> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#ffffff" font-size=".5em" width="20cm"> <fo:table-column column-width="47%"/> <fo:table-column column-width="6%"/> <fo:table-column column-width="47%"/> <fo:table-body> <fo:table-row> <fo:table-cell></fo:table-cell> <fo:table-cell text-align="center" border-width="0.02mm" position="relative" top="-2.2mm"> <fo:block background-color="#ffffff">16800</fo:block> </fo:table-cell> <fo:table-cell></fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#eeeeee" font-size=".5em" width="20cm" height="0.1cm"> <fo:table-body> <fo:table-row> <fo:table-cell border-width="0.02mm" border-bottom-style="solid" border-left-style="solid" border-right-style="solid" /> @for(var j = 0; j < 50; j++) { <fo:table-cell border-width='0.02mm' border-right-style="solid" border-bottom-style="solid" /> } </fo:table-row> </fo:table-body> </fo:table> <fo:table background-color="#eeeeee" font-size=".5em" width="20cm" height="0.5cm"> <fo:table-body> <fo:table-row> @for(var j = 0; j < 20; j++) { <fo:table-cell text-align="center"> <fo:block>2400</fo:block> </fo:table-cell> } </fo:table-row> </fo:table-body> </fo:table> </fo:flow> </fo:page-sequence> </fo:root> </umbraco:Macro> </asp:content>
Hi - The good news is that this is repeatable and it is a bug that can be fixed.
The bad news is that I can't put a time on it just now. e.g. it is likely to be next week.
Thanks for taking the time to report this.
Hi again,
Glad that it isn't just me - as it was driving me crazy...
I'll just make a smaller prototype with less content for my presentation, but gonna hold you up on next week, as I really need this working :-P
Thanks for your fast reply and awesome package :-)
Cheers, Casper
See your inbox - just tried a quick patch.
I have the same issue.
I'am also testing the plugin locally. In my code, I counted the number of lines to be parsed (content from richtext-editor, textstring and so on) to about 100 in <fo:region-body> - if I add another line, it will crash ...
My code:
<%@ Master Language="C#" MasterPageFile="~/masterpages/PDFMaster.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="PdfContentPlaceHolder" runat="server">
<umbraco:Macro runat="server" language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
@using FergusonMoriyama.Pdf
@using System.Xml
@using umbraco.IO
@{
Response.ContentType = "text/xml";
Response.AppendHeader("X-Pdf-Render","true");
// -- Uncomment this to force the browser to download the PDF.
// Response.AppendHeader("X-Pdf-Force-Download","cv.pdf");
}
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ibex="http://www.xmlpdf.com/2003/ibex/Format">
<!-- Sets standard PDF Metadata -->
<ibex:properties
title="@Model.pdfName"
author="@Model.WriterName"
subject=""
keywords="metat,bacon,sheep"
creator="PDF Creator for Umbraco" />
<!-- Uncomment below to add protection to the PDF - optionally specify a password -->
<!-- <ibex:security deny-print="true" deny-extract="true" deny-modify="true" user-password="" owner-password=""/> -->
<!-- This defines a simple page layout with a heder and a footer -->
<!-- See http://www.w3schools.com/xslfo/obj_layout-master-set.asp -->
<fo:layout-master-set>
<fo:simple-page-master master-name="master" page-width="210mm" page-height="297mm" margin-top="2cm" margin-bottom="0cm" margin-left="2cm" margin-right="2cm">
<fo:region-body margin-top="0cm" margin-bottom="2.5cm" column-count="2" column-gap="1cm" color="#6b6b6b"/>
<fo:region-before region-name="header" extent="0cm" margin-bottom="0cm" color="#ffffff" />
<fo:region-after region-name="footer" extent="2cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<!-- Main content starts within page sequence -->
<fo:page-sequence master-reference="master">
<!-- Document header -->
<fo:flow flow-name="header">
</fo:flow>
<!-- Document footer -->
<fo:static-content flow-name="footer">
<!-- Baggrundsbillede - ramme -->
<fo:block-container
absolute-position="absolute"
top="-27.7cm" left="-2cm" width="21cm" height="29.7cm"
background-image="url('http://client.shc.dk/cra/pdf-bg.jpg')"
background-position="top">
<fo:block/>
</fo:block-container>
<fo:block font-size="8pt" color="#aaaaaa">
<fo:block text-align-last="justify">
CV - @Model.pdfName - @DateTime.Now
<fo:leader leader-pattern="space"/>
Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page"/>
</fo:block>
</fo:block>
</fo:static-content>
<!-- Document Body -->
<fo:flow flow-name="xsl-region-body" font-family="Arial" font-size="8pt">
<!-- Logo -->
<fo:block-container
width="8cm" height="2.4cm"
background-image="url('http://client.shc.dk/cra/pdf-logo.jpg')"
background-position="top right"
background-repeat="no-repeat"
>
<fo:block/>
</fo:block-container>
<!-- Billede -->
<fo:block-container
absolute-position="absolute"
left="90mm"
top="0mm"
z-index="1"
>
<fo:block>
@ParseRichText(FoHelper.Instance.GetRichTextNodes(@Model.pdfImage))
</fo:block>
</fo:block-container>
<!-- Stamdata -->
<fo:block-container span="all" padding-bottom="1cm" font-family="Arial" font-size="8pt" width="8cm">
<fo:block>
<fo:inline font-family="Arial" font-weight="bold" font-size="10pt">@Model.pdfName</fo:inline>
</fo:block>
<fo:block>
<fo:inline>Address: @Model.pdfAddress</fo:inline>
</fo:block>
<fo:block>
<fo:inline>Mobile: @Model.pdfMobile</fo:inline>
</fo:block>
<fo:block>
<fo:inline>Email: @Model.pdfEmail</fo:inline>
</fo:block>
<fo:block>
<fo:inline>Homepage: @Model.pdfHomepage</fo:inline>
</fo:block>
<fo:block>
<fo:inline>Date of Birth: @Model.pdfDateOfBirth</fo:inline>
</fo:block>
</fo:block-container>
<!-- CV -->
<fo:block>
@ParseRichText(FoHelper.Instance.GetRichTextNodes(@Model.BodyText))
</fo:block>
<fo:block>
@ParseRichText(FoHelper.Instance.GetRichTextNodes(@Model.BodyText2))
</fo:block>
<fo:block>
Signature __________________________________________
</fo:block>
<!-- Having this before the closing tag of the body flow allows us to have a pager in the footer -->
<fo:block id="last-page" keep-together.within-page="auto"></fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
@helper ParseElement(XmlNode node) {
<!-- @node.Name -->
switch(node.Name)
{
case "p":
<fo:block margin-bottom="0.4cm">
@ParseRichText(node.ChildNodes)
</fo:block>
break;
case "h2":
<fo:block margin-bottom="0.2cm" font-family="Arial" font-size="8pt" color="#ffffff" background-color="#B0BC22" padding-left="1mm" margin-left="0.5mm" padding-top="0.5mm" padding-bottom="0.5mm" >
@ParseRichText(node.ChildNodes)
</fo:block>
break;
case "strong":
<fo:inline font-weight="bold">
@ParseRichText(node.ChildNodes)
</fo:inline>
break;
case "em":
<fo:inline font-style="italic">
@ParseRichText(node.ChildNodes)
</fo:inline>
break;
case "a":
<fo:basic-link color="blue" text-decoration="underline" external-destination="url('@node.Attributes["href"].Value')">
@ParseRichText(node.ChildNodes)
</fo:basic-link>
break;
case "u":
<fo:inline text-decoration="underline">
@ParseRichText(node.ChildNodes)
</fo:inline>
break;
case "ol":
<fo:list-block margin-bottom="0.5cm">
@ParseRichText(node.ChildNodes)
</fo:list-block>
break;
case "ul":
<fo:list-block margin-bottom="0.5cm">
@ParseRichText(node.ChildNodes)
</fo:list-block>
break;
case "li":
<fo:list-item>
<fo:list-item-label>
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block margin-left="0.3cm">
@ParseRichText(node.ChildNodes)
</fo:block>
</fo:list-item-body>
</fo:list-item>
break;
case "img":
var docRoot = IOHelper.MapPath("~/");
<fo:block>
<fo:external-graphic src="@docRoot/@node.Attributes["src"].Value" content-width="8cm"/>
</fo:block>
@ParseRichText(node.ChildNodes)
break;
case "table":
<fo:table width="100%" border="1px solid #e4e4e4" margin-bottom="12pt" border-spacing="0">
@ParseRichText(node.ChildNodes)
</fo:table>
break;
case "tbody":
<fo:table-body>
@ParseRichText(node.ChildNodes)
</fo:table-body>
break;
case "thead":
<fo:table-header number-rows-spanned="4" border-bottom="1px solid #d1d1d1" background="#e4e4e4" padding="3pt" font-weight="bold">
<fo:table-row>@ParseRichText(node.ChildNodes)</fo:table-row>
</fo:table-header>
break;
case "tr":
<fo:table-row>
@ParseRichText(node.ChildNodes)
</fo:table-row>
break;
case "th":
<fo:table-cell number-rows-spanned="" border-bottom="1px solid #d1d1d1" background="#e4e4e4" padding="3pt" font-weight="bold">
<fo:block>@ParseRichText(node.ChildNodes)</fo:block>
</fo:table-cell>
break;
case "td":
<fo:table-cell border="1px solid #e4e4e4" padding="3pt">
<fo:block>@ParseRichText(node.ChildNodes)</fo:block>
</fo:table-cell>
break;
}
}
@helper ParseRichText(XmlNodeList nodes) {
foreach(XmlNode node in nodes) {
switch(node.NodeType)
{
case XmlNodeType.Text:
@node.Value
@ParseRichText(node.ChildNodes);
break;
case XmlNodeType.Element:
@ParseElement(node);
break;
default:
@ParseRichText(node.ChildNodes);
break;
}
}
}
</umbraco:Macro>
</asp:Content>
Best regards
Kim
Hi Kim, I've just released a patch 2.1.1 - can you try it out and see if it helps?
Hi Darren,
It works!!!! Thanks
Best regards
Kim
is working on a reply...