Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Bellow is code

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

public partial class Compassion_forms_Parternship_Committee : System.Web.UI.Page
{
    ReportDocument children = new ReportDocument();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
  protected void btnPrintRegisteredChild_Click(object sender, EventArgs e)
    {
        //Code For Printing Out The Registered Children
        try
        {
            using (DataSetCompassion childrenlist = new DataSetCompassion())
            {
                using (DataSetCompassionTableAdapters.childrenTableAdapter childrens = new DataSetCompassionTableAdapters.childrenTableAdapter())
                {
                    childrens.FillByChildren(childrenlist.children, txtChildApproval.Text);

                }

                crChildrenViewer.Visible = true;
                children.Load(Server.MapPath("~/CrystalReportChildren.rpt"));
                children.SetDataSource(childrenlist);
                crChildrenViewer.ReportSource = children;
                children.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "receipt");
                children.Dispose();


            }
        }
        catch (Exception ex)
        {

            lblPrintChildError.Text = ex.Message.ToString();
        }
    }
Posted
Comments
Bernhard Hiller 24-Sep-14 9:37am    
Which line produces that error?
Richard MacCutchan 24-Sep-14 12:11pm    
The message is telling you what the problem is, you need to investigate why the file is not correctly formatted.

1 solution

%Pdf (0x25 0x50 0x44 0x46) is the magic number for PDF files. This means that a valid PDF file should start with these bytes. It appears that the code involved in writing the PDF to the temp folder before printing is not writing it in a correct format (or at least not using the magic number).

I would start with trying the 'file' command on the temp file generated to see what kind of information it can tell you. For instance, is it not a PDF but rather a RTF etc.

If that fails to give you any information, you could try to do a hexdump or xxd on the temp file in the error message which might tell you if it is empty/malformed etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900