label printer incorrectly prints itextsharp documents - c#

the code below generate pdf documents:
using (FileStream fs = new FileStream("st.csv", FileMode.Open))
{
using (StreamReader configFile = new StreamReader(fs, System.Text.Encoding.GetEncoding("windows-1250")))
{
string line = string.Empty;
while ((line = configFile.ReadLine()) != null)
{
if (!string.IsNullOrEmpty(line))
{
line = line.Replace("\"", "");
string[] varible = line.Split(';');
string number = varible[0];
string stName = varible[1];
string ewidenceNumber = varible[2];
string fileName = "barcodes\\" + Encryption.RandomString(10, true) + ".png";
Generate(line, fileName);
PdfPTable Table = new PdfPTable(2);
Table.WidthPercentage = 100;
Table.SetWidths(new[] { 110f, 190f });
iTextSharp.text.Image barcode = iTextSharp.text.Image.GetInstance(fileName);
barcode.Border = 0;
barcode.ScalePercent(180f);
PdfPCell imageCell = new PdfPCell(barcode);
imageCell.VerticalAlignment = Element.ALIGN_MIDDLE;
Table.AddCell(imageCell);
PdfPCell descriptionCell = new PdfPCell(new Paragraph(
"Enterprise 1 \n\n" +
number + "\n\n" +
"Number1: " + stName + "\n\n" +
"Number2: " + ewidenceNumber, _standardFont));
descriptionCell.HorizontalAlignment = Element.ALIGN_CENTER;
descriptionCell.VerticalAlignment = Element.ALIGN_MIDDLE;
Table.AddCell(descriptionCell);
Table.KeepTogether = true;
Table.SpacingAfter = 10f;
doc.Add(Table);
}
}
}
}
and here is the problem: vertical and horizontal view in adobe acrobat displays correctly, but when I need to print labels with this information CITIZEN label printer always prints it in horizontal view. I can't adapt this data to print in correct orientation. Anyone has solution for this problem? Maybe I incorrectly rotate cells in table?

I would suggest you drop PDF and instead write to it's native format: http://www.citizen-europe.com/support/progman.htm
PDF printing support is supplied by the driver. If the driver doesn't know how to interpret the specific PDF commands then it's not going to work. Usually label printers don't provide very good driver support for anything but writing to their native format or emulating ZPL (zebra) and Datamax.

Related

I can't place an image on a docx document programmatically generated

I am building a desktop application that generates a .docx document with data that I pull from an SQLite database. I am using Xceed's DocX Nuget package to build it, and I can write text without any complication.
However, my application needs to place an image ON THE HEADER. I pull the image with ease from the database, but I fail when I try to send it to the .docx file.
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "Documento Word (*.docx)|*.docx",
FileName = "Documento " + obj_eObra.ProcesoDeSeleccion + ".docx",
DefaultExt = ".docx"
};
if (saveFileDialog.ShowDialog() == true)
{
DocX document = DocX.Create(saveFileDialog.FileName);
Stream Logo = new MemoryStream(obj_eEmpresa.Logo);
Xceed.Document.NET.Image image = document.AddImage(Logo);
document.AddHeaders();
document.AddFooters();
// Force the first page to have a different Header and Footer.
document.DifferentFirstPage = true;
// Force odd & even pages to have different Headers and Footers.
document.DifferentOddAndEvenPages = true;
// Insert a Paragraph into the first Header.
document.Headers.First.Images.Add(image);
// Insert a Paragraph into this document.
var p = document.InsertParagraph();
// Append some text and add formatting.
p.Append("This is a simple formatted red bold paragraph")
.Font(new Font("Arial"))
.FontSize(25)
.Color(System.Drawing.Color.Red)
.Bold()
.Append(" containing a blue italic text.").Font(new Font("Times New Roman")).Color(System.Drawing.Color.Blue).Italic()
.SpacingAfter(40);
document.Save();
}
I expect to see a file that has an image in the header and the following paragraph in the body of the document:
"This is a simple formatted red bold paragraph containing a blue italic text.
But my file only has text, no image.
I did it! Here's the solution
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "Documento Word (*.docx)|*.docx",
FileName = "Documento " + obj_eObra.ProcesoDeSeleccion + ".docx",
DefaultExt = ".docx"
};
if (saveFileDialog.ShowDialog() == true)
{
DocX document = DocX.Create(saveFileDialog.FileName);
Stream Logo = new MemoryStream(obj_eEmpresa.Logo);
Xceed.Document.NET.Image image = document.AddImage(Logo);
document.AddHeaders();
document.AddFooters();
// Force the first page to have a different Header and Footer.
document.DifferentFirstPage = true;
// Force odd & even pages to have different Headers and Footers.
document.DifferentOddAndEvenPages = true;
// Insert a Paragraph & image into the first Header.
var picture = image.CreatePicture();
var p = document.Headers.First.InsertParagraph("");
p.AppendPicture(picture);
p.SpacingAfter(30);
// Insert a Paragraph into this document.
Paragraph CiudadYFecha = document.InsertParagraph();
// Append some text and add formatting.
CiudadYFecha.Append("\n\n\n" + obj_eObra.Ciudad + ", " + obj_eObra.FechaActual + ".\n\nSeñores: " + "\n" + obj_eObra.Cliente + "\n\nAtt.: Comité de Selección " + "\nRef.: " + "<Insertar adjudicacion> " + "N° " + obj_eObra.ProcesoDeSeleccion)
.Font(new Font("Times New Roman"))
.FontSize(12)
.SpacingAfter(40);
Paragraph Cuerpo = document.InsertParagraph("De nuestra consideración: \n\n" + "Es grato dirigirnos a ustedes en atención al proceso de selección de la referencia, para alcanzarles nuestra oferta técnico – económica.\n\n" + "Sin otro particular, nos suscribimos de ustedes,\n\n" + "Atentamente,\n");
Cuerpo.Font(new Font("Times New Roman"))
.FontSize(12)
.SpacingAfter(40);
document.Save();
}

Using iTextSharp to copy TableLayoutPanels to pdf

Good Afternoon everyone. I have a question involving taking data in a tablelayoutpanel and placing it into a .pdf using iTextSharp (Unless someone knows a better technology). The tableLayout panel consists of 1 column with 1 row by default and has rows dynamically added given what the data returns.
Here is what I have for printing:
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "Save file as...";
dialog.Filter = "Pdf File |*.pdf";
if (dialog.ShowDialog() == DialogResult.OK)
{
Document doc = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(dialog.FileName, FileMode.Create));
doc.Open();
Paragraph entry1 = new Paragraph("Hello World!");
//Page 1 Printing
PdfPTable LegendsForTable = new PdfPTable(this.tblPnlLayLFT.ColumnCount);
doc.Add(entry1);
doc.Close();
MessageBox.Show("File saved");
}
}
catch (Exception exception)
{
MessageBox.Show(#"ERROR: Issue encountered while trying to print. " + Environment.NewLine
+ #"Contact ITSupport with the following the following error" + Environment.NewLine
+ exception);
}
}
Does anyone know a method to copy tablelayoutpanel to .pdf?
I was able to figure this out myself.
Step 1 was to create a loop that iterates through the table layout panels and place the order that I want into a list.
int reIterator = 1;
int replicateIterator = 1;
List<string> table1List = new List<string>();
for (int counter = 0; counter < 6; counter++)
{
while (reIterator < 7)
{
string currentLabel = "LblRE" + reIterator + "R" + replicateIterator;
Label reLabel = this.Controls.Find(currentLabel, true).FirstOrDefault() as Label;
if (reLabel.Text != null)
{
table1List.Add(reLabel.Text);
reIterator = reIterator + 1;
}
else
{
table1List.Add(reLabel.Text = "");
reIterator = reIterator + 1;
}
}
//Builds next row
if (reIterator == 7)
{
replicateIterator = replicateIterator + 1;
reIterator = 1;
}
}
Then using iTextSharp I am able to loop through using the list and add the data to a PDF.

c# Printing a PDF with iTextSharp

I have a problem with printing a pdf.
So my Document is being created by writing some values in a pdf document and saving it
public void CreateDocument(string name)
{
string oldreport = #"..\Resources\FehlerReport.pdf";
string newreportpath = #"..\Resources\" + name;
using (var newFileStream = new FileStream(newreportpath, FileMode.Create))
{
var pdfReader = new PdfReader(oldreport);
var stamper = new PdfStamper(pdfReader, newFileStream);
var form = stamper.AcroFields;
var fieldKeys = form.Fields.Keys;
form.SetField("Auftragsnummer", Kundeninformation.Auftragsnummer.ToString());
form.SetField("Kundensachnummer", Kundeninformation.Kundensachnummer.ToString());
form.SetField("Kundenname", Kundeninformation.Kundenname.ToString());
form.SetField("Kundenbestellnummer", Kundeninformation.Kundenbestellnummer.ToString());
form.SetField("Kundenrezepturnummer", Kundeninformation.Kundenrezepturnummer.ToString());
form.SetField("Spulennummer", Kundeninformation.Spulennummer.ToString());
form.SetField("Fertigungsdatum1", System.DateTime.Today.ToString("dd.MM.yy"));
int i = 1;
foreach (var item in _MeasurementReport.MeasurementReportItems)
{
form.SetField(("UhrzeitRow" + i).ToString(), item.Uhrzeit.ToString("HH:mm:ss"));
form.SetField(("FehlerindexRow" + i).ToString(), i.ToString());
form.SetField(("Position mmRow" + i).ToString(), (item.Laufmeter * pixelSize).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));
form.SetField(("HoeheRow" + i).ToString(), (item.DefectCountours.H * pixelSize).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));
form.SetField(("Breite mmRow" + i).ToString(), (item.DefectCountours.W * pixelSize).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));
form.SetField(("Flaeche Row" + i).ToString(), (item.DefectCountours.W * pixelSize * pixelSize).ToString("0.00", System.Globalization.CultureInfo.InvariantCulture));
i++;
}
form.SetField("Datum", System.DateTime.Today.ToString("dd.MM.yy"));
form.SetField("Uhrzeit", System.DateTime.Now.ToString("HH:mm"));
stamper.FormFlattening = true;
stamper.Close();
pdfReader.Close();
}
}
So now i want to print the document with this function, which also calls the CreateDocument function. It prints, but the paper is white. I checked if the created pdf is being created, and it is being created but apparently not printed.
public void Print()
{
string name = Kundeninformation.Auftragsnummer + "_" + Kundeninformation.Spulennummer+".pdf";
CreateDocument(name);
List<string> PrinterFound = new List<string>();
PrinterSettings printer = new PrinterSettings();
foreach (var item in PrinterSettings.InstalledPrinters)
{
PrinterFound.Add(item.ToString());
}
printer.PrinterName = PrinterFound[7];
printer.PrintFileName = name;
PrintDocument PrintDoc = new PrintDocument();
PrintDoc.DocumentName = #"..\Resources\"+name;
PrintDoc.PrinterSettings.PrinterName = PrinterFound[7];
PrintDoc.Print();
}
make sure your file is created completely.. otherwise you will this issue. to test quickly put some delay between file creation and printing

How to introduce superscript in iTextSharp?

I want the output format date like 14th may 2015. the th in 14 it should come with sup tag but sup tag is not accessing here. the output i am getting in ph102 variable. Getsuffix(csq.EventDate.Value.Day) in this only i am getting suffix of th st and rd for date
My code:
PdfPTable table9 = new PdfPTable(4);
table9.WidthPercentage = 99;
table9.DefaultCell.Border = 0;
table9.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
Phrase ph101 = new Phrase("Event Date & Time", textFont2);
PdfPCell cellt1 = new PdfPCell(ph101);
cellt1.Border = PdfPCell.BOTTOM_BORDER + PdfPCell.LEFT_BORDER + PdfPCell.RIGHT_BORDER;
cellt1.PaddingTop = 0F;
cellt1.VerticalAlignment = Element.ALIGN_MIDDLE;
cellt1.HorizontalAlignment = Element.ALIGN_LEFT;
DateTime eventTime = DateTime.Today;
if (!string.IsNullOrEmpty(Convert.ToString(csq.EventTime)))
eventTime = DateTime.Today.Add(csq.EventTime.Value);
Phrase ph102;
if (!string.IsNullOrEmpty(csq.EventDate.ToString()))
{
ph102 = new Phrase(csq.EventDate.Value.Day + Getsuffix(csq.EventDate.Value.Day) + csq.EventDate.Value.ToString("MMM") + " " + csq.EventDate.Value.Year + " at " + eventTime.ToString("hh:mm tt"), textFont7);
}
else
{
ph102 = new Phrase();
}
PdfPCell cellt2 = new PdfPCell(ph102);
cellt2.Border = PdfPCell.BOTTOM_BORDER + PdfPCell.LEFT_BORDER + PdfPCell.RIGHT_BORDER;
cellt2.PaddingTop = 0F;
cellt2.VerticalAlignment = Element.ALIGN_MIDDLE;
cellt2.HorizontalAlignment = Element.ALIGN_LEFT;
When I read your question, I assume that you want something like this:
However, you are confusing people as is demonstrated in the comment from somebody who gives you a hint to use HTML to PDF. Your answer is "no sir it cant work" which is a strange answer, because it can work. It's just not what you meant when you talked about sup tag. At least, that's what I assume when I look at your code, I don't see any HTML.
In your code, you create a Phrase like this:
ph102 = new Phrase(csq.EventDate.Value.Day
+ Getsuffix(csq.EventDate.Value.Day)
+ csq.EventDate.Value.ToString("MMM")
+ " " + csq.EventDate.Value.Year
+ " at " + eventTime.ToString("hh:mm tt"), textFont7);
This complete Phrase is expressed in textFont7 which can't work in your case, because you want to use a smaller font for the "st", "nd", "rd" or "th".
You need to do something like this (see OrdinalNumbers for the full example):
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
Font small = new Font(FontFamily.HELVETICA, 6);
Chunk st = new Chunk("st", small);
st.setTextRise(7);
Chunk nd = new Chunk("nd", small);
nd.setTextRise(7);
Chunk rd = new Chunk("rd", small);
rd.setTextRise(7);
Chunk th = new Chunk("th", small);
th.setTextRise(7);
Paragraph first = new Paragraph();
first.add("The 1");
first.add(st);
first.add(" of May");
document.add(first);
Paragraph second = new Paragraph();
second.add("The 2");
second.add(nd);
second.add(" and the 3");
second.add(rd);
second.add(" of June");
document.add(second);
Paragraph fourth = new Paragraph();
fourth.add("The 4");
fourth.add(rd);
fourth.add(" of July");
document.add(fourth);
document.close();
}
This is the Java code to create the PDF in the screen shot. You'll have to adapt your code so that it works in C#. As you can see, you can not just concatenate your strings using the + operator. You need to compose your Phrase or Paragraph using different Chunk objects. What you call "sup" is done by using a smaller font and a text rise.

Download multiple pdf documents using itextsharp

i have a tree view in which there are certain set of document list and another grid having patient details. what i need to do is when we select docs from treeview (select multiple..checkbox enabled) and patients from grid and click on a button should create all the documents using ITEXTSHARP.that is multiple documents are created. I tried it like this,
on button click
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());
}
}
}
}
}
}
}
}
}
}
and the pdf_abcd function is
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"));
}
and
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();
}
but the system only down loads one doc..can anyone helpme
If you step back and ignore PDFs for a bit and concentrate on just HTTP requests and responses you should have your answer. When a browser makes an HTTP request (your button click) the server is allowed to send one and only one response. You're code is trying (unsuccessfully) to send multiple responses to the browser. The first time that Response.End is called the pipeline gets terminated actually and the rest of your code doesn't run.
The solution is to just make one giant PDF in one pass, make individual PDFs and merge them or create a zip file containing all of the PDFs.
I guess you should create a zip file that combines your PDF files
If you want to Open the file in new tab you have different Methods:
Method 1:
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.pdf");
Response.TransmitFile(filePath);
Response.End();
Method 2:
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = outputPdfFile;
process.Start();
Hope this helps you!

Categories

Resources