PDF form opens in Internet Explorer, but in other browsers displays wingding font

Viewed 65

I am working on a C# project in Visual Studio that takes inputs entered by a user on a webpage and fills in an editable PDF. It will then open that PDF for the user to review and print.

The code works fine in Internet Explorer, but does not work in Edge or Chrome. Instead, it generates a webpage of gibberish, like wingdings.

This project was made by someone else several years ago. I am trying to stumble through it and get it to work since we no longer use Internet Explorer. The relevant code is listed below. I don't know how much detail I can put so I will keep file names and such vague.

As I continue to stumble my way through the code, I noticed that when I try to open the PDF template from Visual Studio's Solution Explorer, I get similar gibberish rather than opening the PDF. Other PDFs open from Solution Explorer fine, but not the template. I wonder if it could be a PDF issue? Here is some of the output I am seeing.

3739 Lines of Gibberish

Here is detailed code. I will modify or remove as little as possible.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.xml;
using System.IO;
using System.Drawing;

namespace ProjectName
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();

            if (!IsPostBack)
            {
                //string mnum = Request.UrlReferrer.Query.ToString().Remove(0, 1);
                //Label1.Text = mnum;
                //string mnum = "1175";
                string mnum = Session["member_num"].ToString();
                urlText.Value = mnum;

                string parms = mnum;
                string indID = null;
                string memNum = null;
                string[] splitParm = new string[1];
                string today = DateTime.Today.ToShortDateString();

                //char[] seperator = new char[] { '&' };
                //string[] arrParms = parms.Split(seperator);
                //char[] seperator2 = new char[] { '=' };
                //string[] MemberNumber = arrParms[0].Split(seperator2);
                //memNum = MemberNumber[1];
                memNum = mnum;
                //Label1.Text = memNum;

                //Label1.Text = arrParms[1];
                //string[] arrParms2 = arrParms[1].Split(seperator2);
                //Label1.Text = arrParms2[1];
                //indID = arrParms2[1]; 
                indID = Session["indv_id"].ToString();
            }
        }

        private void FillForm(string parms, string cbCode1, string cbCode2, string cbCode3, string cbCode4, string cbInqCount, string reason1, string reason2, string reason3, string reason4, string reason5)
        {
            string pdfTemplate = @"Drive:\Web Apps\ProjectName\Forms\Editable_PDF_Fields.pdf";

            string indID = null;
            string memNum = null;
            string[] splitParm = new string[1];
            string today = DateTime.Today.ToShortDateString();

            PdfReader pdfReader = new PdfReader(pdfTemplate);

            //char[] seperator = new char[] { '&' };
            //string[] arrParms = parms.Split(seperator);
            //char[] seperator2 = new char[] { '=' };
            //string[] MemberNumber = arrParms[0].Split(seperator2);
            //memNum = MemberNumber[1];
            memNum = Session["member_num"].ToString();
            //Label1.Text = memNum;

            //Label1.Text = arrParms[1];
            //string[] arrParms2 = arrParms[1].Split(seperator2);
            //Label1.Text = arrParms2[1];
            indID = Session["indv_id"].ToString();

            string[] cbInfo = queryCB(indID);
            string[] cbCodes = { "", "", "", "" };

            string newFile = @"Drive:\Web Apps\ProjectName\Forms\Completed\completed_PDF" + indID + ".pdf";
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
            AcroFields pdfFormFields = pdfStamper.AcroFields;

            if (HiddencbCodes.Value == "Yes")
            {
                string[] arrCodes = new string[] { cbCode1, cbCode2, cbCode3, cbCode4 };
                cbCodes = queryCodes(arrCodes);

                TextBox2.Text = "Text"
                     + Environment.NewLine
                     + Environment.NewLine
                     + cbCodes[0] + Environment.NewLine
                     + cbCodes[1] + Environment.NewLine
                     + cbCodes[2] + Environment.NewLine
                     + cbCodes[3] + Environment.NewLine
                     + Environment.NewLine
                     + "More Text";
            }
            else
            {
                cbCodes[0] = "";
                cbCodes[1] = "";
                cbCodes[2] = "";
                cbCodes[3] = "";
            }

            TextBox1.Text = "Text"
                + Environment.NewLine
                + Environment.NewLine
                + "More Text"
                + Environment.NewLine
                + Environment.NewLine
                + "More Text"
                + Environment.NewLine
                + Environment.NewLine
                + "Text" + cbInfo[2] + "   "
                + "Date: " + cbInfo[3]
                + "Text"
                + Environment.NewLine
                + "Text" + cbInqCount;

            pdfFormFields.SetField("P_D1NAME", cbInfo[1]);
            pdfFormFields.SetField("APL_MEMNBR", memNum);
            pdfFormFields.SetField("LN_EFFDATE", today);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_1", ddlAction.SelectedValue);
            //pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_2", null);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_3", reason1);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_4", reason2);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_5", reason3);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_6", reason4);
            pdfFormFields.SetField("LN_RSN_DECISION_REASON_DESC_7", reason5);
            pdfFormFields.SetField("P_CS_CB_SCORE_1", cbInfo[2]);
            pdfFormFields.SetField("P_CS_CB_REPORT_TIMESTAMP_1", cbInfo[3]);
            pdfFormFields.SetField("P_CB_INQ_COUNT_1", cbInqCount);
            pdfFormFields.SetField("CODE_1", cbCodes[0]);
            pdfFormFields.SetField("CODE_2", cbCodes[1]);
            pdfFormFields.SetField("CODE_3", cbCodes[2]);
            pdfFormFields.SetField("CODE_4", cbCodes[3]);

            if (RadioButtonList1.SelectedValue == "Yes")
            {
                pdfFormFields.SetField("AGENCY_LN_4", TextBox1.Text);
                pdfFormFields.SetField("AGENCY_LN_5", TextBox2.Text);
                pdfFormFields.SetField("AGENCY_1", "1");
            }

            pdfStamper.FormFlattening = false;

            pdfStamper.Close();
            pdfReader.Close();
     
            Server.Transfer("Forms/completed/completed_PDF" + indID + ".pdf");
            OpenFile("Forms/completed/completed_PDF" + indID + ".pdf");

        }

        private string[] queryCB(string id)
        {
            string ind_id = null;
            string ind_name = null;
            string cb_score = null;
            string cb_date = null;

            OdbcConnectionStringBuilder conStr = new OdbcConnectionStringBuilder();
            conStr.Dsn = "database";
            OdbcConnection con = new OdbcConnection(conStr.ConnectionString);
            con.Open();

            string queryNew = "Long SQL Command";

            using (OdbcCommand com = new OdbcCommand(queryNew, con))
            {
                com.Parameters.AddWithValue("@var", id);
                using (OdbcDataReader reader = com.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ind_id = reader.GetString(0);
                        ind_name = reader.GetString(1);
                        cb_score = reader.GetString(2);
                        cb_date = reader.GetString(3);
                    }
                }
            }

            DateTime dt = DateTime.ParseExact(cb_date.Substring(0, 10), "yyyy-MM-dd", CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault);
            string output = String.Format("{0:MM/dd/yyyy}", dt);
            string[] data = new string[] { ind_id, ind_name, cb_score, output };
            con.Close();
            return data;
        }

        private string[] queryCodes(string[] codes)
        {
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = "~~~~~";
            SqlCommand sqlCom = new SqlCommand();
            sqlCom.Connection = cn;
            cn.Open();

            string[] query1 = new string[4];
            int i = 0;
            foreach (string code in codes)
            {
                sqlCom.CommandText = "SELECT description FROM main WHERE code = " + code;
                SqlDataReader rdr = sqlCom.ExecuteReader();
                rdr.Read();
                query1.SetValue(rdr[0].ToString(), i);
                i = i + 1;
                rdr.Close();
            }

            cn.Close();
            return query1;
        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {

        }

        protected void ddlReason1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlReason1.SelectedValue != "Select One...")
                ddlReason2.Enabled = true;
            else
            {
                ddlReason2.Enabled = false;
                ddlReason3.Enabled = false;
                ddlReason4.Enabled = false;
            }
        }

        protected void ddlReason2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlReason1.SelectedValue != "Select One...")
                ddlReason3.Enabled = true;
            else
            {
                ddlReason2.Enabled = false;
                ddlReason3.Enabled = false;
                ddlReason4.Enabled = false;
            }
        }

        protected void ddlReason3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlReason1.SelectedValue != "Select One...")
                ddlReason4.Enabled = true;
            else
            {
                ddlReason2.Enabled = false;
                ddlReason3.Enabled = false;
                ddlReason4.Enabled = false;
            }
        }

        protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (Wizard1.ActiveStepIndex == 1)
            {
                if (RadioButtonList1.SelectedValue == "Yes")
                {
                    Wizard1.ActiveStepIndex = 2;
                    HiddencbCodes.Value = "Yes";
                }
                else
                {
                    Wizard1.ActiveStepIndex = 4;
                }

            }

        }

        protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            string code1 = ddlCode1.SelectedValue.ToString();
            string code2 = ddlCode2.SelectedValue.ToString();
            string code3 = ddlCode3.SelectedValue.ToString();
            string code4 = ddlCode4.SelectedValue.ToString();
            string inqCount = txtInqCount.Text;

            string reas1 = ddlReason1.SelectedValue.ToString();
            string reas2 = ddlReason2.SelectedValue.ToString();
            string reas3 = ddlReason3.SelectedValue.ToString();
            string reas4 = ddlReason4.SelectedValue.ToString();

            if (reas1 == "Select One...")
            {
                reas1 = "";
            }
            if (reas2 == "Select One...")
            {
                reas2 = "";
            }
            if (reas3 == "Select One...")
            {
                reas3 = "";
            }
            if (reas4 == "Select One...")
            {
                reas4 = "";
            }
            string otherReason = txtOther.Text;

            try
            {
                FillForm(Session["member_num"].ToString(), code1, code2, code3, code4, inqCount, reas1, reas2, reas3, reas4, otherReason);
            }
            catch (Exception ex)
            {
                Wizard1.Visible = false;
                Label1.Text = ex.ToString(); 
                //"Text";
            }
        }

        public void TestForReport()
        {

        }
    }
}
0 Answers
Related