Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating header in text 7 , in this header image, line and table
so in first page header showing correctly .But in next page only image logo is showing other line and table is not showing.

What I have tried:

Below i have tried


protected class Header : IEventHandler
{
private Document header;
public Dictionary<int, podcustomer=""> Contentvalue;

public Header(Document doc, Dictionary<int, podcustomer=""> Content)
{
this.header = doc;
this.Contentvalue = Content;
}

public virtual void HandleEvent(Event @event)
{


//PdfPage page = pdf.AddNewPage();



foreach (KeyValuePair<int, podcustomer=""> KV in Contentvalue)
{
PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
PdfFont regular = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
PdfDocument pdf = docEvent.GetDocument();
Document doc = new Document(pdf);

PdfPage page = docEvent.GetPage();
//Rectangle rectangle = page.GetPageSize();
doc.SetMargins(30, 10, 3, 40);
string logoFileName = UserAccount.CompanyLocation.Company.ImageName;
if (System.IO.File.Exists(LogoDirPath + logoFileName))
{

}
else
{

logoFileName = "logo_EvansDelivery.png";
}
string imageSource = LogoDirPath;
ImageData imageData = ImageDataFactory.Create(imageSource + logoFileName);
iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData);
// PdfPage page = pdfDoc.AddNewPage();
PdfCanvas pdfCanvas = new PdfCanvas(page);
Rectangle rectangle = new Rectangle(30, 770, 120, 60);
string proBarcodeString = KV.Value.OrderNumber + "P";

// --Barcode Image code----

Canvas canvas = new Canvas(pdfCanvas, rectangle);
canvas.SetBorder(Border.NO_BORDER);
canvas.Add(image);
//canvas.Close();

iText.Layout.Element.Table th = new iText.Layout.Element.Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth();
Text text1 = new Text(KV.Value.CompanyLocation.LocationName).SetBold();
Text test2 = new Text("Customer Order Detail" + "\n" + "OrderNo:" + KV.Value.OrderNumber).SetBold().SetFontSize(12f);
th.SetHorizontalAlignment(HorizontalAlignment.CENTER);
th.SetMarginLeft(120);
th.AddCell(new Cell().SetTextAlignment(TextAlignment.LEFT).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph("")));
th.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph("\n").Add(new Paragraph(text1))));
th.AddCell(new Cell().SetTextAlignment(TextAlignment.RIGHT).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph(test2)));

LineSeparator lne = new LineSeparator(new SolidLine());

lne.SetMarginLeft(140);
doc.Add(th);
doc.Add(lne);


string wmfBarcodeFileName = ReportDirPath + System.Guid.NewGuid().ToString() + ".wmf";
Evans.Intranet.Common.BarCodeUtils.CreateBarCodeImage(proBarcodeString, wmfBarcodeFileName, .5f);
ImageData imageDatawmf = ImageDataFactory.Create(wmfBarcodeFileName);
iText.Layout.Element.Image barCode = new iText.Layout.Element.Image(imageDatawmf);

Text txt1 = new Text(KV.Value.CompanyLocation.Address + "\n" + KV.Value.CompanyLocation.City + "," + KV.Value.CompanyLocation.State + "," + KV.Value.CompanyLocation.Zip + "\n" + "Phone " + KV.Value.CompanyLocation.Phone + "\n" + "Fax " + KV.Value.CompanyLocation.Fax);
iText.Layout.Element.Table th1 = new iText.Layout.Element.Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth();
Text t1 = new Text("");
Cell cell = new Cell();

cell.Add(barCode.SetAutoScale(true));
cell.SetWidth(0).SetHeight(60);
cell.SetBorder(Border.NO_BORDER);

th1.SetWidth(UnitValue.CreatePercentValue(100));

th1.AddCell(new Cell().SetTextAlignment(TextAlignment.LEFT).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph(""))).SetTextAlignment(TextAlignment.LEFT);
th1.AddCell(new Cell().SetTextAlignment(TextAlignment.CENTER).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph(txt1))).SetTextAlignment(TextAlignment.CENTER);
th1.AddCell(new Cell().SetTextAlignment(TextAlignment.RIGHT).SetBorder(Border.NO_BORDER).SetFont(regular).SetFontSize(10f).Add(new Paragraph("\t")).Add(cell));


doc.Add(th1.SetFontSize(9f));




}

 public static string Generate(Dictionary<int, podcustomer=""> Content, LoadMessage receivedmessage)
        {
            Dictionary<int, podcustomer=""> Contenta = Content;
            string reportfile = Guid.NewGuid().ToString("N") + ".pdf";
            PdfWriter writer = new PdfWriter(ReportDirPath + reportfile);
            PdfDocument pdfDoc = new PdfDocument(writer);
            Document document = new Document(pdfDoc);
           // document.SetMargins(30, 40, 3, 40);

            PdfFont regular = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);

            Header headerHandler = new Header(document, Contenta);
            pdfDoc.AddEventHandler(PdfDocumentEvent.START_PAGE, headerHandler);
)
                
               

            }
        }
Posted

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