Welcome Guest Search | Active Topics | Sign In | Register

Question about ASPXToPDF1.RenderAsPDF(false); Options
anne
Posted: Tuesday, November 27, 2012 3:53:58 PM
Rank: Newbie
Groups: Member

Joined: 3/25/2008
Posts: 7
I want to use ASPXToPDF to programmatically convert and save a document without the document being loaded into the web page. I searched the forums and thought I found a good thread, but the example uses the following

ASPXToPDF1.RenderAsPDF(false); // Call ASPXToPDF1_AfterRender

which doesn't appear to be supported in the version I have

The version of RenderAsPDF that I have just has two options

RenderAsPDF()
RenderAsPDF(filename)

Using either of these is causing the document to be rendered in the browser. Is there a way to just get the document to be saved without viewing it?
eo_support
Posted: Tuesday, November 27, 2012 5:04:10 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
anne
Posted: Tuesday, November 27, 2012 5:49:31 PM
Rank: Newbie
Groups: Member

Joined: 3/25/2008
Posts: 7
That's the one I was looking at, but in my version there is no RenderAsPDF(false). And when I use RenderAsPDF(); it still renders to the web page.
eo_support
Posted: Tuesday, November 27, 2012 5:57:32 PM
Rank: Administration
Groups: Administration

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

In that case you will need to update to the current version as it doesn't appear that feature existed in early versions. The cost of the upgrade is $140. Please let us know if that works for you.

Thanks!
anne
Posted: Thursday, November 29, 2012 2:43:01 PM
Rank: Newbie
Groups: Member

Joined: 3/25/2008
Posts: 7
Ok, I've got the latest version and am handling the AfterRender event. But the content is still being displayed in the browser.

Here is my code:

protected void ASPXToPDF1_AfterRender(object sender, EventArgs e)
{
HtmlToPdfResult result = (HtmlToPdfResult)ASPXToPDF1.Result;
PdfDocument doc = result.PdfDocument;
//Convert to a byte array
MemoryStream stream = new MemoryStream();
doc.Save(stream);
byte[] data = stream.ToArray();
Evaluatee = UiUtils.LookupSEUserFromSecureQueryString(SiteSettings);
long rootFolderId = SiteSettings.RepositoryMgr.Repository(Evaluatee.Id).Root.Id;

RepositoryItem ri = SiteSettings.RepositoryMgr.AddRepoItemWithFirstBitstream(Evaluatee.Id,
rootFolderId, data, "application/pdf", "Snapshot - " + DateTime.Now.ToString(), "snapshot.pdf", ".pdf", string.Empty, data.Length);

SiteSettings.SEMgr.InsertReportSnapshot(SiteSettings.ActiveUser.Id, ri.Id, SiteSettings.CurrentSchoolYear, SEReportType.FINAL);
}

EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat = "<div style='text-align:center'>Page {page_number} </div>";
ReportHelper.LoadReport(evaluatee, true, true);
UiUtils.AddEOPDFLicense();
if (print)
{
ASPXToPDF1.RenderAsPDF("FinalReport.pdf");
}
else
{
ASPXToPDF1.AfterRender += new EventHandler(ASPXToPDF1_AfterRender);
ASPXToPDF1.RenderAsPDF(false);
}

With RenderAsPDF("foo.pdf"), the user is prompted with a Open/Save/Cancel and if you click Open a separate PDF window is opened.

With RenderAsPDF(false), the user is presented with the HTML version of the page in the browser.

My desired behavior is for a user to be viewing the report page and have two buttons: Print and Save. When they click Print a new window with the PDF doc is generated. When they click Save I want to just save out a version of the file to the server and add it to a list of saved versions that are displayed on the page. I can't figure out how to get that functionality to work for the Save case. Any help would be greatly appreciated.

Thanks,

Anne
eo_support
Posted: Thursday, November 29, 2012 3:55:35 PM
Rank: Administration
Groups: Administration

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

You will want to start a new project to get this working and then compare the working project with the non working project. You might have some code in your project that is actually sending the result to the client.

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.