We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Creating a Document or form

I'm just starting out with creating a pdf document and I'm pretty sure I want to create a document vs creating a form, because I'm going to create the form at runtime and the layout can vary.  If I'm going to output a read-only pdf, there is no use in creating a form vs just making a PdfDocument.

The other question is, I want to create a pdf that looks sort of like a form.  For example a text label, like 
Employee ID: 
and a value like 100 to look like:
Name:  Dan                 Employee ID:  100                

I'd want the underlines to show a defined length.  Do I draw a line under them, or is there some thing else I could do?

Also I plan to make a lot of rows, I guess I would add a bunch of rectangles with strings in them, but is there a way to do it like a cursor position, or do I have to get the exact pixel x/y points?





2 Replies

AD Administrator Syncfusion Team July 3, 2012 12:24 AM UTC

Ok, I think the best way to do it is to use pdfGrids.  Then use only the bottom border for the values.  Let me know if I'm on the right track:


                  PdfStringFormat cellFLeft = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Bottom);
                  PdfStringFormat cellFRight = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Bottom);


                  PdfPen noPen = new PdfPen(Colors.Transparent);
                  PdfPen botBorder = new PdfPen(Color.FromArgb(255, 0, 0, 0), 1f);
                  noPen.Width = 1.0f;

                  PdfGridCellStyle labelStyle = new PdfGridCellStyle();
                  labelStyle.Font = font;
                  PdfBorders pdfbNone = new PdfBorders();
                  pdfbNone.All = noPen;
                  labelStyle.Borders = pdfbNone;

                  PdfGridCellStyle valueStyle = new PdfGridCellStyle();
                  valueStyle.Font = font;
                  PdfBorders pdfbBot = new PdfBorders();
                  pdfbBot.Bottom = botBorder;
                  pdfbBot.Top = noPen;
                  pdfbBot.Left = noPen;
                  pdfbBot.Right = noPen;
                  valueStyle.Borders = pdfbBot;

                  PdfGrid grid = new PdfGrid();
               
                  grid.Rows.Add();
                  grid.Columns.Add(3);
                  grid.Rows.ApplyStyle(labelStyle);
                  grid.Rows[0].Cells[0].Value = "Test1";
                  grid.Rows[0].Cells[1].Value = "Test2";
                  grid.Rows[0].Cells[1].Style = valueStyle;

                  grid.Columns[0].Format = cellFRight;
                  grid.Columns[0].Width = 80;
                  grid.Columns[1].Format = cellFLeft;
                  grid.Columns[1].Width = 180;
                 
             
                  PdfLayoutResult resultg = grid.Draw(page, PointF.Empty);





GL George Livingston Syncfusion Team July 3, 2012 08:52 AM UTC

Hi Dan,

Thank you for using Syncfusion Products.

Yes, using PdfGrid to achieve your target is the recommended way.

Please let us know if you have any other questions.

Regards,
George


Loader.
Live Chat Icon For mobile
Up arrow icon