hi paulo,
i am able to hide text on image. i am using tiff image to create pdf. i have a coordinate of text.
through this coordinate i am hiding the text while creating pdf. but hide text is not placed in exact location of coordinate. have you any idea, where i have done mistake.. here is my code..
private void button1_Click(object sender, EventArgs e)
{
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("C:\\Documents and Settings\\Administrator\\Desktop\\TestPdf\\03015-S70-2009_06_16#ACEH_00001205L_New.pdf", FileMode.Create));
System.Drawing.Bitmap bm = new System.Drawing.Bitmap("C:\\Documents and Settings\\Administrator\\Desktop\\TestPdf\\03015-S70-2009_06_16#ACEH_00001205L.TIF");
int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContentUnder;
for (int k = 0; k < total; ++k)
{
bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
img.ScalePercent(72f / img.DpiX * 100);
img.SetAbsolutePosition(0, 0);
img.HasAbsolutePosition();
img.IndentationLeft = 3f;
img.IndentationRight = 3f;
img.ScaleToFit(600f, 850f);
img.CompressionLevel = 300;
cb.AddImage(img);
FnfindText(writer.DirectContent, writer, document);
}
document.Close();
}
//********* This is my function where i am able to find coordinate of text***********//
private void FnfindText(PdfContentByte cb, PdfWriter writer, Document document)
{
int start = 0;
int end = 0;
int height = 0;
int width = 0;
int hpos = 0;
int vpos = 0;
string content = "";
string txt = "";
string file = "";
string AltoPath = "C:\\Documents and Settings\\Administrator\\Desktop\\TestPdf\\03015-S70-2009_06_16#ACEH_00001205L_alto.xml";
StreamReader sr = new StreamReader(AltoPath);
file = sr.ReadToEnd();
int ctst = file.IndexOf("\r\n", 0);
while (ctst != -1)
{
i++;
ctst = file.IndexOf("\r\n", ctst + 1);
}
int v = 0;
start = file.IndexOf("\r\n", v);
while (start != -1)
{
txt = file.Substring(v, start - v);
int Tline = txt.IndexOf("<String ID=", 0);
if (Tline != -1)
{
int TlineEnd = txt.IndexOf("/>", Tline);
if (TlineEnd != -1)
{
string TextLine = txt.Substring(Tline, TlineEnd - Tline + 2);
int Contentst = TextLine.IndexOf("CONTENT=", 0);
if (Contentst != -1)
{
int Contentend = TextLine.IndexOf(" ", Contentst);
if (Contentend != -1)
{
content = TextLine.Substring(Contentst + 9, Contentend - Contentst - 10);
}
}
int Heightst = TextLine.IndexOf("HEIGHT=", 0);
if (Heightst != -1)
{
int HeightEnd = TextLine.IndexOf(" ", Heightst);
if (HeightEnd != -1)
{
height = Convert.ToInt32(TextLine.Substring(Heightst + 8, HeightEnd - Heightst - 9));
}
}
int Widthst = TextLine.IndexOf("WIDTH=", 0);
if (Widthst != -1)
{
int WidthEnd = TextLine.IndexOf(" ", Widthst);
if (WidthEnd != -1)
{
width = Convert.ToInt32(TextLine.Substring(Widthst + 7, WidthEnd - Widthst - 8));
}
}
int HPOSst = TextLine.IndexOf("HPOS=", 0);
if (HPOSst != -1)
{
int HPOSEnd = TextLine.IndexOf(" ", HPOSst);
if (HPOSEnd != -1)
{
hpos = Convert.ToInt32(TextLine.Substring(HPOSst + 6, HPOSEnd - HPOSst - 7));
}
}
int VPOSst = TextLine.IndexOf("VPOS=", 0);
if (VPOSst != -1)
{
int VPOSEnd = TextLine.IndexOf(" ", VPOSst);
if (VPOSEnd != -1)
{
vpos = Convert.ToInt32(TextLine.Substring(VPOSst + 6, VPOSEnd - VPOSst - 7));
}
}
}
ColumnText ct = new ColumnText(cb);
Chunk chunk = new Chunk(content, FontFactory.GetFont(FontFactory.HELVETICA, 10, iTextSharp.text.Color.RED));
chunk.SetTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, 0.0f, iTextSharp.text.Color.RED);
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(hpos, vpos, width, height);
//chunk.SetHorizontalScaling(0.5f);
//rect.GetRectangle(hpos,vpos);
ct.SetSimpleColumn(rect.Left,rect.Bottom, rect.Right, rect.Top);
//ct.SetSimpleColumn(Top, Right, Width, Height);
ct.AddText(chunk);
ct.Go();
}
v = start;
start = file.IndexOf("\r\n", start + 2);
}
}
so, please give me idea....
Thanks & Regards,
Raj