This is a migrated thread and some comments may be shown as answers.

Insert a pdf into telerik reporting

13 Answers 419 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sebastien AUROUX
Top achievements
Rank 1
Sebastien AUROUX asked on 27 Feb 2013, 08:21 AM
Hello
Is it possible to insert a pdf into telerik reporting ? I have a set of reports generated using telerik reporting in pdf format and i want to append another generated pdf. Do you have this feature ?
thanks

13 Answers, 1 is accepted

Sort by
0
Matthias
Top achievements
Rank 1
answered on 28 Feb 2013, 01:25 AM
Would be great if this would be possible! Thumb up for it... It is useful for static pages with a complex layout...
0
Tomas
Top achievements
Rank 1
answered on 28 Feb 2013, 10:55 AM
I think it's been answered before that you have to use a third-party tool for this. But you're right it would be a nice to have feature.

Tomas
0
Stef
Telerik team
answered on 02 Mar 2013, 07:46 AM
Hi everyone,

The feature is not supported in Telerik Reporting as the main goal is data presentation which includes exporting it to various formats. Merging already created PDF files or byte streams can be performed with another software (you can check the forum for other members post about their choice). If you need to unite several reports on export, we can suggest you to use the ReportBook document where you can add different report definitions and export them at once in a single PDF document without additional file merges.

Let us know if you have nay further questions.

Greetings,
Stef
the Telerik team

See what's new in Telerik Reporting Q1 2013. Register for the March 4 webinar to witness the impressive new visualizations in Telerik Reporting. Just for fun, 10 webinar attendees will be randomly selected to win a Telerik T-shirt and a $50 Gift Certificate to ThinkGeek. Register now! Seats are limited!

0
Andy
Top achievements
Rank 1
answered on 19 Jun 2013, 07:50 PM
I agree, this would be a nice feature.  I have a requirement for including documents (pdf, doc, etc.) as part of a report. 
0
Mark
Top achievements
Rank 1
answered on 31 Oct 2016, 12:12 PM

Hey guys

I know I'm late to the party, but has there been any update on this?  While I did read the reply from Stef, I think this would be an awesome feature to have, and would address a large short-fall that I've found in T-Reporting...

I basically need an advanced HTML control to render inside a report.  Since T-Reporting couldn't do this (table layouts, etc.), I have created my own PDF using the Rad Editor export to PDF.  I now need to imbed it into my report...

any ideas?

0
Stef
Telerik team
answered on 31 Oct 2016, 12:23 PM
Hello Mark,

Merging already existing files in a report or rendering of HTML documents is not supported. The workarounds I can suggest you are:
  1. Export the HTML as an Image and use a PictureBox item in the report. Please consider the example here.
  2. Export reports programmatically and merge documents via Telerik Document Processing Libraries.
  3. Use Telerik UI for AJAX or Telerik Kendo UI to export HTML in image, PDF formats - ClientExportManager.


Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jaw
Top achievements
Rank 1
answered on 10 Jan 2017, 01:05 PM

I vote for this feature :-P

there are some business scenario, which we have to generate report and attach some pdf scan data. f.i. #)expenses report with invoice

#)import summary with customs-document

;-)

0
Stef
Telerik team
answered on 10 Jan 2017, 02:31 PM
Hi Jaw,

Thank you for this feedback.

Please check Telerik Document Processing Libraries which allow you to import, merge and export PDF files.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 06 Nov 2017, 09:54 AM

Hi Telerik

 

Like Jaw I now have to print an expenses report with attached pdf invoices.

In my code I´m working with reportbooks. I use them to render them as pdf, to show them in the ReportViewer or to send them directly to the printer. In my architecture it is not really meaningful to merge invoice pdfs after an pdf of the report is created...

 

I really want the possibility to add some pdf files to the report book. Or at least the possibility to include them in a report just like I can add a picture with a PictureBox.

 

What solutions do you have for me?

 

Regards,

Michael

0
Katia
Telerik team
answered on 07 Nov 2017, 07:55 AM
Hi Michael,

Inserting a PDF document into a report is still not supported and it is not in our short-term plans to add this feature. To insert a PDF it would be necessary to use third party libraries for merging documents or merge the files programmatically. You can check Stef's post for more suggestions.


Regards,
Katia
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Johnathan
Top achievements
Rank 1
answered on 11 Apr 2018, 01:35 PM

For those looking for a possible solution, here is a code snippet using open source PDFSharp with Telerik Reporting. (You can also get the source code for free) In this code, I am loading a PDF from a file, creating my own Telerik report and attaching it by pages to that document, and then adding a footer document from a file. ReportProcessor & RenderingResult are Telerik classes, and PdfDocument and PdfReader are PDFSharp classes:

protected void ExportToPDF(InstanceReportSource reportSource)
{
    ReportProcessor reportProcessor = new ReportProcessor();
    RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, null);
 
    long classID = Int64.Parse(Request["cl"]);
    PdfDocument reportHeader = (classID > 1) ?
        PdfReader.Open(Server.MapPath("~\\Reports\\ClassHeader.pdf"), PdfDocumentOpenMode.Import) :
        PdfReader.Open(Server.MapPath("~\\Reports\\UnclassHeader.pdf"), PdfDocumentOpenMode.Import);
    PdfDocument reportMain = PdfReader.Open(new MemoryStream(result.DocumentBytes), PdfDocumentOpenMode.Import);
    PdfDocument reportFooter = (classID > 1) ?
        PdfReader.Open(Server.MapPath("~\\Reports\\ClassFooter.pdf"), PdfDocumentOpenMode.Import) :
        PdfReader.Open(Server.MapPath("~\\Reports\\UnclassFooter.pdf"), PdfDocumentOpenMode.Import);
 
    // Originally tried creating a new PdfDocument and combining all three PDFs,
    // but I could not figure out how to transfer fields from the header page to the combined document.
    // To solve this, I attached the main and footer PDF to the first page.
    // If the footer also has fillable fields, this will be a problem.
    foreach (PdfPage p in reportMain.Pages)
    {
        reportHeader.AddPage(p);
    }
 
    foreach (PdfPage p in reportFooter.Pages)
    {
        reportHeader.AddPage(p);
    }
 
    Response.Clear();
    Response.ContentType = result.MimeType;
 
    using (var ms = new MemoryStream())
    {
        reportHeader.Save(ms, false);
        ms.WriteTo(Response.OutputStream);
    }
    Response.End();
}
0
Hooman
Top achievements
Rank 1
answered on 04 Feb 2021, 09:46 PM

Since it has been 3 years since the last reply, I wanted to check if this functionality is now supported or not yet!

As others have stated, this is a very useful functionality.

0
Johnathan
Top achievements
Rank 1
answered on 04 Feb 2021, 10:44 PM

You can do it in code. My snippet above works; however, I have since changed the code so that it's all done through the Telerik libraries and have removed the PDFSharp library from my project. (I think Telerik may share some internals with it as many properties are similarly named.) The problem I had with the above code was that it was not keeping the fillable fields, but I have since solved that problem. My updated code is below. It inserts a PDF document before my generated documents and adds a footer PDF to the end. You can strip out the digital signature call.

protected void ExportToPDF(InstanceReportSource reportSource, params string[] signatures)
{
    ReportProcessor reportProcessor = new ReportProcessor();
    RenderingResult result = reportProcessor.RenderReport("PDF", reportSource, null);
 
    RadFixedDocument docHeader = new RadFixedDocument();
    RadFixedDocument docFooter = new RadFixedDocument();
    RadFixedDocument document = new RadFixedDocument();
    PdfFormatProvider provider = new PdfFormatProvider();
 
    // Choose approprate selected cover sheets
    long classID = Int64.Parse(Request["cl"]);
    string headerPath = (classID > 1) ? Server.MapPath("~\\Reports\\ClassHeader.pdf") : Server.MapPath("~\\Reports\\UnclassHeader.pdf");
    string footerPath = (classID > 1) ? Server.MapPath("~\\Reports\\ClassFooter.pdf") : Server.MapPath("~\\Reports\\UnclassFooter.pdf");
 
    // Header page to insert
    using (var fs = new FileStream(headerPath, FileMode.Open, FileAccess.Read))
    {
        docHeader = provider.Import(fs);
    }
 
    // Main generated document
    using (var ms = new MemoryStream(result.DocumentBytes))
    {
        document = provider.Import(ms);
 
        foreach (string sig in signatures)
        {
            AddDigitalSignature(document, sig);
        }
    }
 
    // Footer page to insert
    using (var fs = new FileStream(footerPath, FileMode.Open, FileAccess.Read))
    {
        docFooter = provider.Import(fs);
    }
 
    // Entry fields on a form are stored at a document level
    // and must be added to the main document in addition to the page to be retained
    FormFieldCollection headerFields = docHeader.AcroForm.FormFields;
    while (docHeader.Pages.Count > 0)
    {
        RadFixedPage headerPage = docHeader.Pages[0];
        docHeader.Pages.Remove(headerPage);
        document.Pages.Insert(0, headerPage);
    }
    foreach (FormField field in headerFields)
    {
        document.AcroForm.FormFields.Add(field);
    }
 
    // This might allow the fields on the last page to be retained as well
    // Currently the customer hasn't noticed or needed them.
    FormFieldCollection footerFields = docFooter.AcroForm.FormFields;
    while (docFooter.Pages.Count > 0)
    {
        RadFixedPage footerPage = docFooter.Pages[0];
        docFooter.Pages.Remove(footerPage);
        document.Pages.Add(footerPage);
    }
    foreach (FormField field in footerFields)
    {
        document.AcroForm.FormFields.Add(field);
    }
 
    Response.Clear();
    Response.ContentType = result.MimeType;
 
    using (var ms = new MemoryStream(provider.Export(document)))
    {
        ms.WriteTo(Response.OutputStream);
    }
    Response.End();
}
Tags
General Discussions
Asked by
Sebastien AUROUX
Top achievements
Rank 1
Answers by
Matthias
Top achievements
Rank 1
Tomas
Top achievements
Rank 1
Stef
Telerik team
Andy
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Jaw
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Katia
Telerik team
Johnathan
Top achievements
Rank 1
Hooman
Top achievements
Rank 1
Share this question
or