} // RenderPoster /// <summary> /// Responsible for drawing (and downloading) the text example poster. /// </summary> protected void RenderTextPosterExample(HttpContext ctx) { string templateFilename = ctx.Server.MapPath("./Poster-Templates/text-example-template.jpg"); string when = ctx.Request["when"] ?? ""; string where = ctx.Request["where"] ?? ""; string id = ctx.Request["eventId"] ?? ""; // And build the poster and send the response back to the browser PosterDesigns.ExampleText playFootball = new PosterDesigns.ExampleText(templateFilename); string url = string.Format("http://toepoke.co.uk/{0}.aspx", id); // Set the dynamic bits playFootball.Frequency = when; playFootball.Venue = where; playFootball.SignUpLink = url; // Show a border around the areas defined (helps debugging where the rectangles should go) playFootball.ShowGuides = GetShowGuidesParam(ctx); playFootball.ShowDimensions = GetShowGuidesParam(ctx); // Set the size we're after playFootball.PercentSize = GetSizeParam(ctx); // And send back to the browser // .. we're just going to hard-code PNG for the time being PosterBuilder.ImgFormat.SupportedTypes outFmt = GetImageType(ctx); Helpers.SendPosterToBrowser(playFootball, ctx.Response, "football-poster", outFmt); } // RenderTextPosterExample
void Download_Click(object sender, EventArgs e) { string templateFilename = this.Server.MapPath("./Poster-Templates/map-example-template.jpg"); PosterDesigns.ExampleMap poster = new PosterDesigns.ExampleMap(templateFilename); poster.Frequency = Frequency.Text; poster.Venue = Venue.Text; poster.SignUpLink = string.Format("http://toepoke.co.uk/{0}.aspx", this.EventID.Text); poster.ShowGuides = false; poster.ShowDimensions = false; poster.PercentSize = 100; // fullSize when downloading poster.VenueMap.Type(this.MapType.SelectedValue); if (!string.IsNullOrEmpty(this.LatLong.Text)) { poster.VenueMap.Centre(this.LatLong.Text); } else { poster.VenueMap.Centre(this.Address.Text); } PosterBuilder.ImgFormat.SupportedTypes imgType = PosterBuilder.ImgFormat.FromString(PosterRendering.ImageTypes.SelectedValue); Helpers.SendPosterToBrowser(poster, this.Response, "my-poster", imgType); } // Download_Click
public static string BuildFilename(string filenamePrefix, PosterBuilder.ImgFormat.SupportedTypes imgFormat) { string newFilename = ""; string extension = ""; extension = PosterBuilder.ImgFormat.ToFileExtension(imgFormat); newFilename = System.IO.Path.ChangeExtension(filenamePrefix, extension); return(newFilename); }
} // MakePoster_Click void Download_Click(object sender, EventArgs e) { string templateFilename = this.Server.MapPath("./Poster-Templates/voucher-example-template.jpg"); PosterDesigns.ExampleVoucher voucher = new PosterDesigns.ExampleVoucher(templateFilename); voucher.SpecialOffer = SpecialOffer.Text; voucher.OfferFor = OfferFor.Text; voucher.Birthday = DateTime.Parse(Birthday.Text); voucher.ShowGuides = false; voucher.ShowDimensions = false; voucher.PercentSize = 100; // fullSize when downloading PosterBuilder.ImgFormat.SupportedTypes imgType = PosterBuilder.ImgFormat.FromString(PosterRendering.ImageTypes.SelectedValue); Helpers.SendPosterToBrowser(voucher, this.Response, "my-voucher", imgType); } // Download_Click
} // RenderTextPosterExample /// <summary> /// Responsible for drawing (and downloading) the map example poster. /// </summary> protected void RenderMapPosterExample(HttpContext ctx) { string templateFilename = ctx.Server.MapPath("./Poster-Templates/map-example-template.jpg"); string when = GetParm(ctx, "when"); string where = GetParm(ctx, "where"); string id = GetParm(ctx, "eventId"); string latLong = GetParm(ctx, "lat-long"); string address = GetParm(ctx, "address"); string mapType = GetParm(ctx, "map-type"); // And build the poster and send the response back to the browser PosterDesigns.ExampleMap mapPoster = new PosterDesigns.ExampleMap(templateFilename); string url = string.Format("http://toepoke.co.uk/{0}.aspx", id); // Set the dynamic bits mapPoster.Frequency = when; mapPoster.Venue = where; mapPoster.SignUpLink = url; mapPoster.VenueMap .Type( mapType ) ; if (!string.IsNullOrEmpty(latLong)) // use the Lan/Long in preference to the address (better accuracy) mapPoster.VenueMap.Centre(latLong); else mapPoster.VenueMap.Centre(address); // Show a border around the areas defined (helps debugging where the rectangles should go) mapPoster.ShowGuides = GetShowGuidesParam(ctx); mapPoster.ShowDimensions = GetShowGuidesParam(ctx); // Set the size we're after mapPoster.PercentSize = GetSizeParam(ctx); // And send back to the browser // .. we're just going to hard-code PNG for the time being PosterBuilder.ImgFormat.SupportedTypes outFmt = GetImageType(ctx); Helpers.SendPosterToBrowser(mapPoster, ctx.Response, "football-poster", outFmt); } // RenderMapPosterExample
} // RenderMapPosterExample /// <summary> /// Responsible for drawing (and downloading) the example voucher. /// </summary> protected void RenderVoucherExample(HttpContext ctx) { string templateFilename = ctx.Server.MapPath("./Poster-Templates/voucher-example-template.jpg"); // and build the voucher PosterDesigns.ExampleVoucher voucher = new PosterDesigns.ExampleVoucher(templateFilename); // Set the dynamic bits voucher.SpecialOffer = GetParm(ctx, "special-offer"); voucher.OfferFor = GetParm(ctx, "offer-for"); voucher.Birthday = DateTime.Parse(GetParm(ctx, "birthday")); voucher.ShowGuides = GetShowGuidesParam(ctx); voucher.ShowDimensions = GetShowGuidesParam(ctx); voucher.PercentSize = GetSizeParam(ctx); // And send back to the browser // .. we're just going to hard-code PNG for the time being PosterBuilder.ImgFormat.SupportedTypes outFmt = GetImageType(ctx); Helpers.SendPosterToBrowser(voucher, ctx.Response, "your-voucher", outFmt); } // RenderVoucherExample
public static void SendPosterToBrowser(PosterBuilder.Builder pb, HttpResponse resp, string posterFilename, PosterBuilder.ImgFormat.SupportedTypes outputFormat) { string filename = BuildFilename(posterFilename, outputFormat); resp.Clear(); // Ensure caching is off naturally resp.CacheControl = "no-cache"; resp.ContentType = PosterBuilder.ImgFormat.ToMimeType(outputFormat); resp.AddHeader("Content-Disposition", "attachment;filename=" + filename); // Call our image with our amendments and have it save to the response so we can send it back Bitmap bmp = pb.Render(); // Have the Poster build our new image and save the result to the outgoing response // ... have to do all this with MemoryStreams as PNG doesn't like being saved directly to HttpResponse.OutputStream // ... may as well do the same for all image types and be consistent using (Bitmap bitmap = pb.Render()) { using (MemoryStream ms = new MemoryStream()) { ImageFormat outFmt = PosterBuilder.ImgFormat.ToImageFormat(outputFormat); bmp.Save(ms, outFmt); ms.WriteTo(resp.OutputStream); } // using ms } // using pb // And of course, clear up after ourselves pb.Dispose(); resp.End(); }