Welcome Guest Search | Active Topics | Sign In | Register

ASPXToPDF1.RenderAsPDF() Options
K_ing
Posted: Thursday, July 28, 2011 7:00:17 PM
Rank: Newbie
Groups: Member

Joined: 7/28/2011
Posts: 5
ASPXToPDF1.RenderAsPDF() Method generates this error :

"StartIndex cannot be less than zero.
Parameter name: startIndex"

Anytime I have a textbox control on aspx page!


Stack Trace:


[HtmlToPdfException: StartIndex cannot be less than zero.
Parameter name: startIndex]
EO.Pdf.HtmlToPdfException.b(Exception A_0) +104
EO.Pdf.Internal.j5.g() +1707
EO.Pdf.HtmlToPdf.a(j5 A_0) +38
EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc) +88

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +261
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
EO.Web.Internal.dc.a(String A_0, Object A_1) +128
EO.Web.ASPXToPDF.a(String A_0, String A_1) +349
EO.Web.Internal.ma.a(HttpResponse A_0, String A_1) +206
EO.Web.Internal.ip.a(HtmlTextWriter A_0, Control A_1) +309
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266




Any advice would be appreciated.

Thanks.
eo_support
Posted: Thursday, July 28, 2011 7:20:03 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We have not been able to reproduce this problem. Can you create a test project that demonstrates this problem and send it to us? We will email you as to where to send.

Thanks!
Ismael
Posted: Thursday, August 4, 2011 10:56:50 AM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
I am having the same issue: EO.Pdf.HtmlToPdfException: StartIndex cannot be less than zero.

I am using a user control.

printusercontrol.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintUserControl.aspx.cs" Inherits="PrintUserControl" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<%@ Register src="Print.ascx" tagname="Print" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="btnPrint" Text="print"
onclick="btnPrint_Click" />
<eo:ASPXToPDF ID="ASPXToPDF1" runat="server">
</eo:ASPXToPDF>
<uc1:Print ID="Print1" runat="server" />
</div>
</form>
</body>
</html>


code behind for printUserControl.aspx.cs

protected void btnPrint_Click(object sender, EventArgs e)
{
ASPXToPDF1.RenderAsPDF();
}



print.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Print.ascx.cs" Inherits="Print" %>

<div id="brandStartSpacer" />

<div id="brandStart">
<img id="brandStartLogo" src="chrome://branding/content/about-logo.png" alt="" />
</div>

<div id="searchContainer">
<form name="searchForm" id="searchForm" onsubmit="onSearchSubmit(event)">
<div id="searchLogoContainer"><img id="searchEngineLogo" /></div>
<div id="searchInputContainer">
<input type="text" name="q" value="" id="searchText" maxlength="256" />

</div>
<div id="searchButtons">
<input id="searchSubmit" type="submit" value="&abouthome.searchEngineButton.label;" />
</div>
</form>
</div>

<div id="contentContainer">
<div id="snippetContainer">

<div id="defaultSnippets" hidden="true">
<span>&abouthome.defaultSnippet1.v1;</span>
<span>&abouthome.defaultSnippet2.v1;</span>
</div>
<div id="snippets"/>
</div>

<div id="sessionRestoreContainer">
<button id="restorePreviousSession">&historyRestoreLastSession.label;</button>

</div>
</div>

<div id="bottomSection">
<div id="aboutMozilla">
<a href="http://www.mozilla.com/about/">&abouthome.aboutMozilla;</a>
</div>
</div>


I dont have any code behind in the Print.ascx.cs
eo_support
Posted: Thursday, August 4, 2011 11:20:18 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We tested your code and it still works fine. Are there any specific steps that we have to follow in order to reproduce the problem? Also can you put them into a separate test project and send the test project to us?

Thanks!
Ismael
Posted: Thursday, August 4, 2011 11:30:47 AM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
just emaild to the support account a test project I been working with. it's a 3mb attachment.
eo_support
Posted: Thursday, August 4, 2011 11:54:30 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Yes. We have received it. Thank you!
Ismael
Posted: Thursday, August 4, 2011 12:49:20 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
Where you able to reproduce using the sample project?
eo_support
Posted: Thursday, August 4, 2011 12:50:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We have looked into the test project. We received a different error:

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Our steps are:

1. Load the project with Visual Studio 2008;
2. Run PrintUserControl.aspx;
3. Click "print" button at the top of the page;

This error is normal and it is caused by you having two nesting form elements in your page. This is invalid. In your PrintUserControl.aspx, you have a form "form1". Inisde your Print.ascx you have another form searchForm. You can have more than one form elements in the same page, but you can not have one nested inside another. It may appear to work fine in some cases but it can cause strange problems in some other cases.

To resolve the issue, move your search form outside of the parent form. For example, you can change your code in PrintUserControl.aspx from:

Code: HTML/ASPX
<form id="form1" runat="server">
<div>
    <asp:Button runat="server" ID="btnPrint" Text="print" 
        onclick="btnPrint_Click" />
    <eo:ASPXToPDF ID="ASPXToPDF1" runat="server">
    </eo:ASPXToPDF>
    <uc1:Print ID="Print1" runat="server" />    
</div>
</form>


To:

Code: HTML/ASPX
<form id="form1" runat="server">
<div>
    <asp:Button runat="server" ID="btnPrint" Text="print" 
        onclick="btnPrint_Click" />
    <eo:ASPXToPDF ID="ASPXToPDF1" runat="server">
    </eo:ASPXToPDF>
</div>
</form>
<uc1:Print ID="Print1" runat="server" />


Note "uc1:Print" is no longer inside form1. That should resolve the problem.

Please let us know if what you see is different.

Thanks!
Ismael
Posted: Thursday, August 4, 2011 1:28:20 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
I took out the extrat form tag from the ascx file, I get no errors but the pdf does not get rendered on the form, did it load for you?
eo_support
Posted: Thursday, August 4, 2011 1:33:48 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We don't see any issues once we moved up1:Print out of the parent form. Can you elaborate what you mean by "took out extra form tag" (removing it all together or move it) and "pdf does not get rendered" (no pdf generated at all or pdf generated but certain contents are missing or something else)?

Thanks!
Ismael
Posted: Thursday, August 4, 2011 1:33:51 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
The error shows up when you click on the print button, and for some reason the "html to pdf" does not do anthing even after removing the extra form tag

I tried to call the rendera as pdf with and without specifying the file name ASPXToPDF1.RenderAsPDF("print.pdf");

Server Error in '/EO ASPX to PDF' Application.
StartIndex cannot be less than zero.
Parameter name: startIndex
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: EO.Pdf.HtmlToPdfException: StartIndex cannot be less than zero.
Parameter name: startIndex

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HtmlToPdfException: StartIndex cannot be less than zero.
Parameter name: startIndex]
EO.Pdf.HtmlToPdfException.b(Exception A_0) +104
EO.Pdf.Internal.j1.g() +1707
EO.Pdf.HtmlToPdf.a(j1 A_0) +38
EO.Pdf.HtmlToPdf.ConvertHtml(String html, PdfDocument doc) +88

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +71
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +261
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
EO.Web.Internal.dc.a(String A_0, Object A_1) +128
EO.Web.ASPXToPDF.a(String A_0, String A_1) +355
EO.Web.Internal.ma.a(HttpResponse A_0, String A_1) +206
EO.Web.Internal.ir.a(HtmlTextWriter A_0, Control A_1) +311
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
eo_support
Posted: Thursday, August 4, 2011 1:55:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
No. We do not see this error. Also please confirm:

1. Once removing the extra form element, there is nothing left in the page except for the "print" button (inside PrintUserControl.aspx) and an image (inside Print.ascx). Only FireFox recognizes that image (so we do not recognize that image);

2. You said "for some reason the "html to pdf" does not do anything even after removing the extra form tag", then said it caused an error. Are you referring two different actions here? If so, what are the steps to cause the "StartIndex cannot be less than zero" error?

Thanks!
Ismael
Posted: Thursday, August 4, 2011 2:12:34 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
There are two buttons on the printusercontrol.aspx page there is a "print" (left one, top of page) and a "html to PDF" (right one, top of page) button.

when you click on the the "html to pdf" not pdf comes up. I cant see the actual pdf after the code behind execute, this is the actual code behind the "HTML to PDF" button:

EO.Pdf.HtmlToPdf.ConvertUrl(Request.Url.Scheme + "://" + Request.Url.Authority + "/EO ASPX to PDF/bing.aspx", "print.pdf");

(this should convert to pdf the bing.aspx page inside this same project)

When I say I removed the extra form tag I removed it from the user control page. this is the code I left on the user control page "print.ascx"

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Print.ascx.cs" Inherits="Print" %>
<%@ OutputCache Duration="1" VaryByParam="none" %>

<div id="brandStartSpacer" />

<div id="brandStart">
<img id="brandStartLogo" src="chrome://branding/content/about-logo.png" alt="" />
</div>

<div id="searchContainer">

<div id="searchLogoContainer"><img id="searchEngineLogo" /></div>
<div id="searchInputContainer">
<input type="text" name="q" value="" id="searchText" maxlength="256" />

</div>
<div id="searchButtons">
<input id="searchSubmit" type="submit" value="&abouthome.searchEngineButton.label;" />
</div>
</div>

<div id="contentContainer">
<div id="snippetContainer">

<div id="defaultSnippets" hidden="true">
<span>&abouthome.defaultSnippet1.v1;</span>
<span>&abouthome.defaultSnippet2.v1;</span>
</div>
<div id="snippets"/>
</div>

<div id="sessionRestoreContainer">
<button id="restorePreviousSession">&historyRestoreLastSession.label;</button>

</div>
</div>

<div id="bottomSection">
<div id="aboutMozilla">
<a href="http://www.mozilla.com/about/">&abouthome.aboutMozilla;</a>
</div>
</div>


Now as far as the top left "Print" button, this just calls the ASPXToPDF1.RenderAsPDF();

The code for the PrintUserControl.aspx is as follow.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PrintUserControl.aspx.cs" Inherits="PrintUserControl" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>


<%@ Register src="Print.ascx" tagname="Print" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button runat="server" ID="btnPrint" Text="print"
onclick="btnPrint_Click" />

<asp:Button runat="server" ID="btnHTMLtoPDF" Text="html to pdf"
onclick="btnHTMLtoPDF_Click" />

<eo:ASPXToPDF ID="ASPXToPDF1" runat="server">
</eo:ASPXToPDF>
<uc1:Print ID="Print1" runat="server" />
</div>
</form>
</body>
</html>


I also tried the changes you recommended but I still get same error when I click on the "print" button.
eo_support
Posted: Thursday, August 4, 2011 2:31:38 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We updated the code and here is the new result:

1. Now we see two buttons at the top: "print" and "html to pdf". This agrees with you;

2. Clicking "html to pdf" seems to "do nothing". This agrees with you;

3. Clicking "print" renders the PDF fine. This disagrees with you;

#2 is correct. ConvertUrl outputs to a file or a PdfDocument object. It does not send the output to client (people can use that call in a non-Web application). In your case, your second argument is "print.pdf", so it actually creates such a PDF file for you somewhere on your system (the exact location depends on your current working directory. For example, in our test system it's c:\Program Files\Microsoft Visual Studio 9.0\Common 7\IDE\print.pdf). If you give it an absolute file path such as c:\print.pdf, then it will create c:\print.pdf. This has nothing to do with your Web application or Web client;

#3 appears to be the only remaining issue now. We have not been able to reproduce it here. There must be something different between your configuration (project setup, directory, etc) and ours. It is possible for you to share your desktop to us so that we can take a look on your machine? We use Citrix GoToMeeting to do remote sessions and we can setup the session for you.

Thanks!
Ismael
Posted: Thursday, August 4, 2011 2:44:33 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
that would be great... the email i sent with the test project there you should have my number, please call me to setup GoToMeeting.
eo_support
Posted: Friday, August 5, 2011 4:13:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

We have posted a new build that should fix this problem. Please check your email for download location.

Thanks!
Ismael
Posted: Friday, August 5, 2011 7:14:43 PM
Rank: Member
Groups: Member

Joined: 2/3/2009
Posts: 28
I did not get the email with the fix, can you please resent it, thanks.
eo_support
Posted: Friday, August 5, 2011 7:17:28 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
I have resent the link to you via private message through the forum. You can click "Inbox" at the top of the forum to view the messages.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.