2013-06-19 3 views
0

문서 목록과 환자 세부 정보가있는 다른 표가있는 트리보기가 있습니다. 내가 할 필요가있는 것은 treeview (select multiple ... checkbox enabled)에서 문서를 선택하고 그리드에서 환자를 선택하고 버튼을 클릭하면 ITEXTSHARP를 사용하여 모든 문서를 작성해야하는 경우입니다. 여러 문서가 작성되었습니다. 나는 버튼을 클릭itextsharp를 사용하여 여러 pdf 문서 다운로드

foreach(TreeNode node in TreeView1.Nodes) 
    { 
     if (node.ChildNodes.Count>0) 
     { 
      for(int i=0 ;i<(node.ChildNodes.Count);i++) 
      { 
       if (node.ChildNodes[i].Checked==true) 
       { 
        string nodevalue = node.ChildNodes[i].Value.ToString(); 

        if (nodevalue=="3") 
        { 
         foreach (GridViewRow row in GridView1.Rows) 
          { 
           if (row.RowType == DataControlRowType.DataRow) 
           { 
            CheckBox chk = row.FindControl("CheckBox1") as CheckBox; 
            if (chk.Checked) 
            { 
             Label lbl_name = row.FindControl("Label1") as Label; 
             Label lbl_dob = row.FindControl("Label3") as Label; 
             pdf_abcd(lbl_name.Text.Trim(), lbl_dob.Text.Trim()); 
            } 
           } 
          } 
        } 


        } 
       } 
      } 
     } 
    } 


} 

에이 같은

을 그것을 시도하고 pdf_abcd 기능은

public void pdf_abcd(string name, string dob) 
{ 
    Phrase hospt_name = new Phrase(); 
    Phrase slogan = new Phrase(); 
    Phrase address = new Phrase(); 
    Phrase pat_name = new Phrase(); 
    Phrase phr_Consent_For_Treatment = new Phrase(); 
    Phrase phr_Professional_Care = new Phrase(); 
    Phrase phr_Consent_For_Treatment_head = new Phrase(); 
    Phrase phr_Professional_Care_head = new Phrase(); 
    Phrase phr_Nursing_Care = new Phrase(); 
    Phrase phr_Nursing_Care_head = new Phrase(); 
    Phrase phr_signtur_line = new Phrase(); 
    Phrase phr_signtur_bigfont = new Phrase(); 
    Phrase phr_signtur_smallfont_line = new Phrase(); 
    Phrase phr_signtur_date_line = new Phrase(); 
    Phrase phr_relationship = new Phrase(); 
    Phrase phr_witness = new Phrase(); 
    Phrase phr_paitient_name = new Phrase(); 
    Phrase phr_paitient_dob = new Phrase(); 

    Paragraph para = new Paragraph(); 
    Paragraph pat_det = new Paragraph(); 
    Paragraph Consent_For_Treatment = new Paragraph(); 
    Paragraph Professional_Care = new Paragraph(); 
    Paragraph Nursing_Care = new Paragraph(); 
    Paragraph Consent_For_Treatment_head = new Paragraph(); 
    Paragraph Professional_Care_head = new Paragraph(); 
    Paragraph Nursing_Care_head = new Paragraph(); 
    Paragraph signatur = new Paragraph(); 
    Paragraph relationship = new Paragraph(); 
    Paragraph witness = new Paragraph(); 
    Paragraph paitient_name_dob = new Paragraph(); 

    Font fntNormalText = FontFactory.GetFont(FontFactory.TIMES, 12, iTextSharp.text.Font.NORMAL); 
    Font fntBoldText = FontFactory.GetFont(FontFactory.TIMES, 12, Font.BOLD); 
    Font fntsmallText = FontFactory.GetFont(FontFactory.TIMES, 8, Font.NORMAL); 
    Font fntverysmallText = FontFactory.GetFont(FontFactory.TIMES, 6, Font.NORMAL); 
    Font fntBoldheadingText = FontFactory.GetFont(FontFactory.TIMES, 10, Font.BOLD); 
    Font fntparaText = FontFactory.GetFont(FontFactory.TIMES, 10, Font.NORMAL); 


    hospt_name = new Phrase("abcd", fntBoldText); 
    slogan = new Phrase(System.Environment.NewLine + "Quality health care here at home", fntNormalText); 
    address = new Phrase(System.Environment.NewLine + "P.O. Box 677", fntsmallText); 
    para.Add(hospt_name); 
    para.Add(slogan); 
    para.Add(address); 

    phr_paitient_name = new Phrase(System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + name + "                      " + dob, fntNormalText); 

    pat_name = new Phrase(System.Environment.NewLine + "__________________________________________________________               _______________________________" + System.Environment.NewLine + "Patient's Name                                       D.O.B.", fntsmallText); 

    pat_det.Add(phr_paitient_name); 
    pat_det.Add(pat_name); 


    phr_Consent_For_Treatment_head = new Phrase(System.Environment.NewLine + "Consent For Treatment", fntBoldheadingText); 
    Consent_For_Treatment_head.Add(phr_Consent_For_Treatment_head); 

    phr_Consent_For_Treatment = new Phrase("The undersigned consents to procedures and treatments which may be performed during this hospitalization or on an outpatient or emergency basis, including but not limited to anesthesia, laboratory procedures, medical or surgical treatments, x-ray examination, or other services rendered under the general and specific instructions of the physician, physician's assistant, nurse practitioner or Designee. In order to manage accidental exposure of a health care worker to blood or other bodily fluids, the undersigned further consents to such testing; including but not limited to AIDS, TB, Syphilis, and Hepatitis testing, as may be necessary for protection of the heath care worker.", fntparaText); 
    Consent_For_Treatment.Add(phr_Consent_For_Treatment); 

    phr_Professional_Care_head = new Phrase(System.Environment.NewLine + "Professional Care", fntBoldheadingText); 
    Professional_Care_head.Add(phr_Professional_Care_head); 

    phr_Professional_Care = new Phrase("The attending physician, usually selected by the patient except under unusual or emergency circumstances, is the professional who arranges for the patient's care and treatment Doctors of medicine, including anesthesia provider, pathologists, radiologists, emergency room physicians, osteopathy, podiatry, etc., are independent contractors and are not employees of Val Verde Regional Medical Center. You will receive a separate bill from the physician/anesthesia provider.", fntparaText); 
    Professional_Care.Add(phr_Professional_Care); 

    phr_Nursing_Care_head = new Phrase(System.Environment.NewLine + "Nursing Care", fntBoldheadingText); 
    Nursing_Care_head.Add(phr_Nursing_Care_head); 

    phr_Nursing_Care = new Phrase("The hospital provides general nursing care. Private duty nursing must be arranged by the patient's representative. The hospital is not responsible for and is released from all liabilities for failure to provide such care.", fntparaText); 
    Nursing_Care.Add(phr_Nursing_Care); 


    phr_signtur_line = new Phrase(System.Environment.NewLine + System.Environment.NewLine + "__________________________________________________________________________________________   ________________", fntsmallText); 
    phr_signtur_bigfont = new Phrase(System.Environment.NewLine + "Signature of Patient/Responsible Party/Patient Representative", fntNormalText); 
    phr_signtur_smallfont_line = new Phrase("(If patient unable to sign)", fntverysmallText); 
    phr_signtur_date_line = new Phrase("  Date ", fntNormalText); 

    signatur.Add(phr_signtur_line); 
    signatur.Add(phr_signtur_bigfont); 
    signatur.Add(phr_signtur_smallfont_line); 
    signatur.Add(phr_signtur_date_line); 

    phr_relationship = new Phrase(System.Environment.NewLine + "______________________________________________________________" + System.Environment.NewLine + "Relationship to patient", fntNormalText); 
    relationship.Add(phr_relationship); 


    phr_witness = new Phrase(System.Environment.NewLine + "___________________________________            __________" + System.Environment.NewLine + "Signature of Witness                       Date", fntNormalText); 
    witness.Add(phr_witness); 


    Document Doc = new Document(PageSize.A4, 0, 0, 25, 50); 




    PdfWriter.GetInstance(Doc, new FileStream(Server.MapPath("~/abcd/abcd.pdf"), FileMode.Create)); 

    Doc.Open(); 

    PdfPTable table = new PdfPTable(1); 

    table.TotalWidth = 500f; 

    table.LockedWidth = true; 

    iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("~/img/abcd.png"); 
    logo.ScaleAbsolute(30, 30); 

    PdfPCell image_header = new PdfPCell(logo); 
    image_header.HorizontalAlignment = Element.ALIGN_CENTER; 
    image_header.BorderWidth = 0; 

    table.AddCell(image_header); 

    PdfPCell header = new PdfPCell(para); 
    header.HorizontalAlignment = Element.ALIGN_CENTER; 
    header.Colspan = 4; 
    header.BorderWidth = 0; 
    table.AddCell(header); 

    PdfPCell patient = new PdfPCell(pat_det); 
    patient.BorderWidth = 0; 
    table.AddCell(patient); 

    //PdfPCell patientname = new PdfPCell(new Phrase(System.Environment.NewLine + System.Environment.NewLine + "Patient's Name                  D.O.B.")); 
    //patientname.BorderWidth = 0; 
    //table.AddCell(patientname); 

    PdfPCell head_treatment = new PdfPCell(new Phrase(Consent_For_Treatment_head)); 
    head_treatment.BorderWidth = 0; 
    table.AddCell(head_treatment); 

    PdfPCell treatment_content = new PdfPCell(Consent_For_Treatment); 
    treatment_content.BorderWidth = 0; 
    table.AddCell(treatment_content); 



    PdfPCell head_profcare = new PdfPCell(Professional_Care_head); 
    head_profcare.BorderWidth = 0; 
    table.AddCell(head_profcare); 

    PdfPCell profcare_content = new PdfPCell(Professional_Care); 
    profcare_content.BorderWidth = 0; 
    table.AddCell(profcare_content); 




    PdfPCell head_nursing = new PdfPCell(Nursing_Care_head); 
    head_nursing.BorderWidth = 0; 
    table.AddCell(head_nursing); 

    PdfPCell nursing_content = new PdfPCell(Nursing_Care); 
    nursing_content.BorderWidth = 0; 
    table.AddCell(nursing_content); 



    PdfPCell sig = new PdfPCell(signatur); 
    sig.BorderWidth = 0; 
    table.AddCell(sig); 



    PdfPCell raltntopatient = new PdfPCell(relationship); 
    raltntopatient.BorderWidth = 0; 
    table.AddCell(raltntopatient); 



    PdfPCell witnesslines = new PdfPCell(witness); 
    witnesslines.BorderWidth = 0; 
    table.AddCell(witnesslines); 

    Doc.Add(table); 

    Doc.Close(); 
    string path = Server.MapPath("~/abcd/Dabcd.pdf"); 

    ShowPdf(path); 
    //Response.Redirect(Server.MapPath("~/abcd/abcd.pdf")); 


} 

private void ShowPdf(string strS) 
{ 
    Response.ClearContent(); 
    Response.ClearHeaders(); 
    Response.ContentType = "application/pdf"; 
    Response.AddHeader("Content-Disposition", "attachment; filename=" + strS); 
    Response.TransmitFile(strS); 
    Response.End(); 
    Response.Flush(); 
    Response.Clear(); 

} 

하지만 시스템에만로드 한 문서 다운 .. 누구든지 도울 수있다

답변

0

PDF 파일을 결합한 zip 파일을 만들어야한다고 생각합니다.

+0

HttpContext.Current.Response.ContentType = "애플리케이션/PDF" HttpContext.Current.Response.AddHeader ("내용 처리", "첨부 파일, 파일 이름 = GridViewExport.pdf") HttpContext.Current.Response.Cache. SetCacheability (HttpCacheability.NoCache) 새 문서() PdfWriter.GetInstance (pdfDoc, HttpContext.Current.Response.OutputStream) pdfDoc.Open() '쓰기 PDF pdfDoc.Add (새 단락으로 희미한 pdfDoc ("내 첫 번째 PDF ")) '끝내기 쓰기 >>>>> pdfDoc.Close() HttpContext.Current.Response.Write (pdfDoc) HttpContext.Current.Response.End() .. 새 탭에서 열 방법 – Sivajith

3

조금만 돌아가서 PDF를 무시하고 HTTP 요청과 응답에만 집중한다면 답을 얻어야합니다. 브라우저가 HTTP 요청 (버튼 클릭)을하면 서버는 응답을 하나만 보낼 수 있습니다. 당신은 코드가 여러 응답을 브라우저에 보내려하고 있습니다 (실패한 경우). 처음으로 Response.End이라는 파이프 라인이 호출되면 실제로 종료되고 나머지 코드는 실행되지 않습니다.

하나의 거대한 PDF를 한 번에 작성하고 개별 PDF를 만들고 모든 PDF가 포함 된 mergethem 또는 create a zip 파일을 만드는 것이 해결책입니다.

방법 1 :

Response.Clear(); 
Response.ContentType = "application/pdf"; 
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf"); 
Response.TransmitFile(filePath); 
Response.End(); 

방법 2 :

Process process = new Process(); 
process.StartInfo.UseShellExecute = true; 
process.StartInfo.FileName = outputPdfFile; 
process.Start(); 

희망이 당신을 도와줍니다 당신이 file in new tabOpen하려면

+0

... 또는 일부 AJAX 마법 수행 ... – mkl

0

당신은 다른 방법이있다!

관련 문제