c# - iTextSharp: Rectangle is not showing in Acrobat Reader -


i'm using itextsharp v5.1. create pdf file multiple pages. when open pdf in chrome looks expected, when open in systemviewer of win8 parts of context missing. , in acrobat reader parts missing well.

i managed track down problem: when draw line, rectangle or roundedrectangle following text not showing anymore until create new page.

i'm writing text, no images , have no form objects. when analyze pdf using http://www.pdf-online.com/osa/repair.aspx get

page  objno  description 0      0  form xobject xf2 has empty or unreadable content stream. 9      0  file corrupt , cannot repaired. of contents can possibly recovered. 

searching day understand xf2 has forms, don't use.

here's code create document:

        var document = new document();         document.setpagesize(pagesize.a4.rotate());         var writer = pdfwriter.getinstance(document, ms);          // set template title page         titlepageeventhandler("template.pdf"));         writer.setpdfversion(pdfwriter.pdf_version_1_7);         writer.pdfversion = pdfwriter.version_1_7;          // open document         document.open();          // add metatags         document.addtitle("my title");         document.addsubject("my subject");         document.addauthor("me");         document.addcreator("itextsharp v5.1");         document.addcreationdate();         document.addproducer(); 

this code write text:

        protected static float showtext(         pdfcontentbyte cb,          font font,          float x,          float y,          float width,          float height,          string text,          bool simulate = false,          int alignment = element.align_left)     {         var phrase = new phrase(new chunk(text, font));         var column = new columntext(cb);         column.setsimplecolumn(x, y, x + width, y - height, lineheight, element.align_left | element.align_top);         column.settext(phrase);         column.alignment = alignment;         column.go(simulate);         return column.lineswritten * lineheight;     } 

and code of drawing rectangle:

        protected static void drawrectangle(         pdfcontentbyte cb,          basecolor strokecolor,          basecolor fillcolor,          float left,          float top,          float right,          float bottom)     {         cb.setcolorstroke(strokecolor);         cb.setcolorfill(fillcolor);         cb.setlinedash(0, 0); // no dashed line         cb.moveto(left, top);         cb.lineto(right, top);         cb.lineto(right, bottom);         cb.lineto(left, bottom);         cb.closepathfillstroke();     } 

this draw line:

        protected static void drawline(         pdfcontentbyte cb,         basecolor strokecolor,         float left,         float top,         float right,         float phase = 0)     {         cb.setcolorstroke(strokecolor);         if (phase >= 0)         {             cb.setlinedash(phase, phase); <== line causing problem         }          cb.moveto(left, top);         cb.lineto(right, top);         cb.stroke();     } 

when call showtext , next drawrectangle , showtext pdf showing ok in chrome, in other viewers first text shown , nothing after it. without drawrectangle pdf, including headers , footers rendered ok in viewers.

please advice how solve this.


Comments

Popular posts from this blog

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -