Welcome Guest Search | Active Topics | Sign In | Register

Saving PDF without sending to client - strange behaviour Options
RvanOlst
Posted: Saturday, April 27, 2013 4:22:58 AM
Rank: Newbie
Groups: Member

Joined: 4/27/2013
Posts: 5
Hello Support,

I'm using ASPXToPDF to create a pdf file of my company's website. We provide the customer with two methods:
- Download the pdf file (in code: ASPXToPDF.RenderAsPDF(PdfFilename);)
- Email the pdf file (in code: ASPXToPDF.RenderAsPDF(false);, with post processing)

The page is a dashboard, so in order to provide our users with a useful pdf, we load an additional css file when the page is rendered by the ASPXToPDF. This is necessary since we need to change certain margins.

The issue we're noticing is that there seems to be a difference between the two methods after the rendering has completed. The resulting pdf looks perfect and the first method works great. The second method however causes the client's window to be redrawn, showing the rendered page of the pdf.

In other words:

Code:
if (toBeEmailed)
{
    ASPXToPDF.RenderAsPDF(false); // Causes rendering to display on client's screen.
}
else
{
    ASPXToPDF.RenderAsPDF(PdfFilename); // Works fine.
}


There is no difference in the method ASPXToPDF_BeforeRender() for either method, and no code is executed in ASPXToPDF_AfterRender().

I'm at a loss what causes this behaviour, and I don't know how to further debug it. Can you shed a light on this?

With kind regards,

Robin van Olst
eo_support
Posted: Saturday, April 27, 2013 12:07:57 PM
Rank: Administration
Groups: Administration

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

You may want to test your code in a blank project. RenderAsPDF(false) should not do anything. All it does is to perform a conversion in the memory, so nothing should be output to the client side unless you have other code somewhere else.

Thanks!
RvanOlst
Posted: Saturday, April 27, 2013 2:50:49 PM
Rank: Newbie
Groups: Member

Joined: 4/27/2013
Posts: 5
Thanks for the response, I will try that soon. On a related note, I'd like to ask: what is the best method to add css to rendered pdf? Currently I've defined this in the header:

Code:

    <asp:PlaceHolder ID="PlaceHolder1" runat="server">
      <%= (this.Response.Filter.ToString().StartsWith("EO.Web") ? "<link rel=\"stylesheet\" href=\"" +
            ResolveClientUrl("~/Content/css/style_aspxtopdf.css") +
            "\"  />" : "") %>
    </asp:PlaceHolder>


This works, but it could be the source of my problems. Is there a better way?

With kind regards,

Robin van Olst
eo_support
Posted: Saturday, April 27, 2013 4:28:14 PM
Rank: Administration
Groups: Administration

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

You can not use server side output code when using ASPXToPDF. You must use server controls to do that. For example, you can use a Label control and then set that Label's Text to whatever raw HTML you want to use.

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.