4 Answers, 1 is accepted

I don't believe the ExportContent event is raised when exporting to PDF, only RTF. I've tried it myself and the event was never raised for PDF exporting.

Once I have resolved the issue, I will share the code to add custom headers and footers.
RadEditor's ExportContent event is fired for ExportToPdf and ExportToRtf methods. At present, it is not possible to cancel or interrupt the default execution of ExportToRtf() and ExportToPdf() methods of RadEditor.
However, we always try to improve RadControls and we will consider the implementation of such functionality. Unfortunately, I am unable to provide you a firm estimate. I will bookmark this ticket and write back to you as soon as we get more details on the subject.
Best wishes,
Dobromir
the Telerik team

private
float FooterHeight = 0;
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Calculate the height of the footer if applicable and set the margins apprpriately
iTextSharp.text.
Image CMlogo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/images/HeaderFooter/MyFooter.png"));
CMlogo.ScalePercent(32);
FooterHeight = CMlogo.ScaledHeight;
PdfDesigner.ExportToPdf();
}
private PdfPTable GetHeaderFooterTable(string url, float documentWidth)
{
//I use a PdfPtable with 1 column to position my header where I want it
PdfPTable headerTbl = new PdfPTable(1);
//set the width of the table to be the same as the document
headerTbl.TotalWidth = documentWidth;
//I use an image logo in the header so I need to get an instance of the image to be able to insert it. I believe this is something you couldn't do with older versions of iTextSharp
iTextSharp.text.
Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(url));
//I used a large version of the logo to maintain the quality when the size was reduced. I guess you could reduce the size manually and use a smaller version, but I used iTextSharp to reduce the scale. As you can see, I reduced it down to 32% of original size.
logo.ScalePercent(32);
//create instance of a table cell to contain the logo
PdfPCell cell = new PdfPCell(logo);
//align the logo to the right of the cell
cell.HorizontalAlignment =
Element.ALIGN_LEFT;
//add a bit of padding to bring it away from the right edge
cell.PaddingRight = 20;
//remove the border
cell.Border = 0;
//Add the cell to the table
headerTbl.AddCell(cell);
//I use a PdfPtable with 1 column to position my header where I want it
return headerTbl;
}
protected void PdfDesigner_ExportContent(object sender, Telerik.Web.UI.EditorExportingArgs e)
{
float width = 595;
float height = 841;
//Get the generated PDF as byte array
Byte[] info = System.Text.Encoding.Default.GetBytes(e.ExportOutput);
stream =
new MemoryStream();
iTextSharp.text.
Document document = new iTextSharp.text.Document(new Rectangle(width, height), 0, 0, 0, 0);
PdfReader reader = new PdfReader(info);
PdfWriter writer = PdfWriter.GetInstance(document, stream);
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int rotation;
int n = reader.NumberOfPages;
PdfPTable headerTbl = new PdfPTable(1);
PdfPTable footerTbl = new PdfPTable(1);
headerTbl = GetHeaderFooterTable(
"~/images/HeaderFooter/MyHeader.png", document.PageSize.Width);
footerTbl = GetHeaderFooterTable(
"~/images/HeaderFooter/MyFooter.png", document.PageSize.Width);
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(new Rectangle(width, height));
document.NewPage();
if (rdoHeaderFooter.SelectedValue != "0")
{
headerTbl.WriteSelectedRows(0, -1, 0, (document.PageSize.Height), writer.DirectContent);
footerTbl.WriteSelectedRows(0, -1, 0, FooterHeight, writer.DirectContent);
}
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (page.Height < page.Width)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, height);
}
else
{
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
writer.CloseStream =
false;
document.Close();
Response.Clear();
Response.ContentType =
"application/pdf";
Response.AddHeader(
"Content-Disposition", "inline;attachment; filename=" + "File.pdf");
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.Close();
}