Hi Paulo, i corrected the prob.,issue got resolved but code not working as required its not printing Page # of ... # is missing Pls suggest me what to do?
Paulo Soares-3 wrote: > > For each EndText() you must have a BeginText(). > > Paulo > > ----- Original Message ----- > From: "swati jain" <[email protected]> > To: <[email protected]> > Sent: Thursday, August 06, 2009 10:11 AM > Subject: Re: [iText-questions] Illegal operation 'Tm' outside a text > object > using DirectUnderContent > > > > Hi all, > > I am having same prob while printing pg # of # on pdf doc. Pls tell me > whats going wrong with following code > > public override void OnEndPage(PdfWriter writer, Document document) > { > > base.OnStartPage(writer, document); > Phrase header = new Phrase("**** THIS IS HEADER PART OF THIS PDF ****"); > PdfPTable footer = new PdfPTable(2); > footer.TotalWidth = 575; > footer.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; > footer.DefaultCell.Border = Rectangle.NO_BORDER; > Font Headerfont = FontFactory.GetFont(FontFactory.HELVETICA, 10, > Font.NORMAL, new Color(64, 64, 171)); > footer.AddCell(new Phrase(new Chunk(" Visit Index", Headerfont) > SetAction(new PdfAction(PdfAction.FIRSTPAGE)))); > > int intGoToPageNo = 3; > if (HttpContext.Current.Session["PageNoVisit"] != null) > { > if (HttpContext.Current.Session["PageNoVisit"] != "0") > { > intGoToPageNo = > Convert.ToInt32(HttpContext.Current.Session["PageNoVisit"].ToString()); > } > } > footer.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; > PdfAction action = PdfAction.GotoLocalPage(intGoToPageNo, new > PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer); > footer.AddCell(new Phrase(new Chunk(" Visit Summary", Headerfont) > SetAction(action))); > PdfContentByte cb = writer.DirectContent; > > > //ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, header, > (document.Right - document.Left) / 2 + document.LeftMargin, document.Top + > 10, 0); > footer.WriteSelectedRows(0, -1, (document.Right - document.Left) / 2 + > document.LeftMargin - 300, document.Top + 35, cb); > if (HttpContext.Current.Session["Footer"] == "Billing Summary ") > { > // document.SetMargins(document.Left, document.Right, document.Top + 300, > document.Bottom); > // document.SetPageSize(PageSize.A3); > Rectangle page = document.PageSize; > PdfPTable head = new PdfPTable(2); > head.TotalWidth = 376; > head.DefaultCell.Border = Rectangle.NO_BORDER; > string FilePath11 = HttpContext.Current.Server.MapPath("images") + "\\" + > "compex.bmp"; > iTextSharp.text.Image imgDoc11 = > iTextSharp.text.Image.GetInstance(FilePath11); > imgDoc11.ScaleAbsoluteHeight(1); > imgDoc11.ScaleToFit(1,1); > imgDoc11.Alignment = iTextSharp.text.Image.ALIGN_CENTER | > iTextSharp.text.Image.ALIGN_TOP; > head.AddCell(""); > // head.AddCell(new Phrase(new Chunk(" "))); > Font Headfont = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD | > Font.UNDERLINE, Color.BLACK); > head.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; > head.AddCell(new Phrase(new Chunk(" BILLING SUMMARY ", Headfont))); > > head.WriteSelectedRows(0, -1, (document.Right - document.Left) / 2 + > document.LeftMargin - 300, document.Top + 26, cb); > > > } > > > base.OnEndPage(writer, document); > PdfContentByte moCB = writer.DirectContent; > > String sText; > Single fLen; > > > int intCount = 0; > if (HttpContext.Current.Session["PreFooter"] != null) > { > if (HttpContext.Current.Session["PreFooter"].ToString() != > HttpContext.Current.Session["Footer"].ToString()) > { > if (HttpContext.Current.Session["PreFooter"].ToString() == "Visit Index ") > { > int intPageNoVisit = writer.PageNumber; > intPageNoVisit = intPageNoVisit + 1; > HttpContext.Current.Session["PageNoVisit"] = intPageNoVisit.ToString(); > > } > document.ResetPageCount(); > document.ResetFooter(); > } > } > > > HttpContext.Current.Session["PreFooter"] = > HttpContext.Current.Session["Footer"].ToString(); > > sText = HttpContext.Current.Session["Footer"].ToString(); > if (sText == "CPX1 ") > { > sText = "CPX "; > } > > int iPageNumber = writer.PageNumber; > iPageNumber = iPageNumber + 1; > //intPageNo[i] = writer.PageNumber; > if (sText == "CPX ") > { > sText = "SRC "; > if(iPageNumber<10) > sText = sText + "00000" + iPageNumber.ToString(); > else if((iPageNumber>=10) && (iPageNumber<100)) > sText = sText + "0000" + iPageNumber.ToString(); > else if ((iPageNumber >= 100) && iPageNumber < 1000) > sText = sText + "000" + iPageNumber.ToString(); > else if ((iPageNumber >= 1000) && iPageNumber < 10000) > sText = sText + "00" + iPageNumber.ToString(); > } > else > { > //sText = ""; > //sText = sText + "00000" + iPageNumber.ToString(); > if (sText == "Visit Index ") > sText = PrintPageNo("IDX ", iPageNumber); > if (sText == "Chronological Visit Summary ") > sText = PrintPageNo("VSM ", iPageNumber); > if (sText == "Billing Summary ") > sText = PrintPageNo("BSM", iPageNumber); > } > //if(sText=="") > // if(iPageNumber==1) > // { > // HttpContext.Current.Session["intVisitSummaryPageNo"] = > > > //fLen = moBF.GetWidthPoint(sText, 8); > //moCB.BeginText(); > //moCB.SetFontAndSize(moBF, 8); > //moCB.SetTextMatrix(document.PageSize.Width - 100, 10); > //moCB.ShowText(sText); > //moCB.EndText(); > cb.SaveState(); > cb.SetTextMatrix(document.Right - 45, document.Bottom - 20); > cb.SetFontAndSize(moBF, 8); > cb.ShowText(sText + "of "); > cb.EndText(); > cb.RestoreState(); > > > > //moTemplate = moCB.CreateTemplate(50, 50); > //moTemplate.BeginText(); > //moTemplate.SetFontAndSize(moBF, 8); > //moTemplate.ShowText((writer.PageNumber - 1).ToString()); > //moTemplate.EndText(); > //moCB.AddTemplate(moTemplate, document.PageSize.Width - 90 + fLen, 30); > //moCB.BeginText(); > //moCB.SetFontAndSize(moBF, 8); > //moCB.SetTextMatrix(280, 820); > //moCB.EndText(); > //'---Line just above footer > //moCB.MoveTo(30, 40) > //moCB.LineTo(oDocument.PageSize.Width - 40, 40) > //moCB.Stroke() > > > > > } > > public string PrintPageNo(string sText, int iPageNumber) > { > if (iPageNumber < 10) > sText = sText + "00000" + iPageNumber.ToString(); > else if ((iPageNumber >= 10) && (iPageNumber < 100)) > sText = sText + "0000" + iPageNumber.ToString(); > else if ((iPageNumber >= 100) && iPageNumber < 1000) > sText = sText + "000" + iPageNumber.ToString(); > else if ((iPageNumber >= 1000) && iPageNumber < 10000) > sText = sText + "00" + iPageNumber.ToString(); > return sText; > } > > // Public Sub OnOpenDocument( _ > // ByVal writer As iTextSharp.text.pdf.PdfWriter, _ > // ByVal document As iTextSharp.text.Document) _ > // Implements iTextSharp.text.pdf.IPdfPageEvent.OnOpenDocument > // Try > // moBF = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, > BaseFont.NOT_EMBEDDED) > // moCB = writer.DirectContent > // moTemplate = moCB.CreateTemplate(50, 50) > // Catch de As DocumentException > // Catch ioe As IOException > // End Try > //End Sub > > public override void OnCloseDocument(PdfWriter writer, Document document) > { > base.OnCloseDocument(writer, document); > PdfContentByte cb = writer.DirectContent; > cb.BeginText(); > cb.SetFontAndSize(moBF, 12); > cb.SetTextMatrix(document.Right - 5, document.Bottom - 20); > cb.ShowText(writer.PageNumber.ToString()); > cb.EndText(); > > } > > > > SALERNI ACHILLE wrote: >> >> I need to put in each page of my Pdf a text as background, using >> getUnderContent, I read in archive that Illegal operation 'Tm' outside a >> text object is generated by a wrong position in code but I don't >> understand where I have to put it, because I don't have direct call to >> beginText and endText() . This error is generated just if i try to write >> in underContent. >> >> >> >> .............. >> Document document = new Document(); >> >> try{ >> >> PdfWriter writer = PdfWriter.getInstance(document, new >> FileOutputStream(namePdf)); >> Phrase p = null; >> >> document.open(); >> >> Font courier8 = new Font(Font.COURIER, 8); >> Font courier8b = new Font(Font.COURIER, 8); >> courier8b.setStyle(Font.BOLD); >> bf= BaseFont.createFont("c:\\windows\\fonts\\arialuni.ttf", >> BaseFont.IDENTITY_H, true); >> >> >> Chunk c = new Chunk(riga_norm, courier8);//riga_norm is a string >> Chunk cb = new Chunk(riga_bold, courier8b);//riga_bold is a string >> >> p = new Phrase(10, ""); >> p.add(cb); >> p.add(c); >> >> >> if (newPage){ >> document.newPage(); >> >> >> /////////////////////////////////////////////////////////////////////par >> t that produce the error >> PdfContentByte under = writer.getDirectContentUnder(); >> under.setColorFill(new Color(220, 220, 220)); >> under.setFontAndSize(bf, 36); >> under.showTextAligned(Element.ALIGN_LEFT, "TEXT", 50, 50, 55); >> under.fill(); >> //////////////////////////////////////////////////////////////////// >> } >> else >> document.add(new Paragraph(p)); >> >> } >> } catch (DocumentException de) { >> System.err.println(de.getMessage()); >> } catch (IOException ioe) { >> System.err.println(ioe.getMessage()); >> } >> >> >> document.close(); >> >> ....................... >> >> >> >> Best regards >> Achille Salerni >> >> > > -- > View this message in context: > http://www.nabble.com/Illegal-operation-%27Tm%27-outside-a-text-object-using-DirectUnderContent-tp4539428p24841052.html > Sent from the iText - General mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.1t3xt.com/docs/book.php > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: > http://1t3xt.info/tutorials/keywords/ > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 > 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > > Buy the iText book: http://www.1t3xt.com/docs/book.php > Check the site with examples before you ask questions: > http://www.1t3xt.info/examples/ > You can also search the keywords list: > http://1t3xt.info/tutorials/keywords/ > > -- View this message in context: http://www.nabble.com/Illegal-operation-%27Tm%27-outside-a-text-object-using-DirectUnderContent-tp4539428p24846891.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
