The HiQPdf Client supports two different modes to layout objects: absolute positioning in a PDF canvas and relative positioning in a PDF document.
With this layout mode you can place objects in a PDF container at fixed coordinates. The method PdfCanvasLayout(PdfObject) can be used to layout objects on the canvas. In the following code sample the objects are positioned in a PDF page container.
// create a page in document
PdfPage page1 = document.AddPage();
float crtYPos = 20;
float crtXPos = 5;
// layout a PdfText object in a PDF page
PdfText titleTextLines = new PdfText(crtXPos, crtYPos, "Lines:", pdfFontEmbed);
titleTextLines.ForeColor = PdfColor.Navy;
page1.Layout(titleTextLines);
// advance the Y position in the PDF page
crtYPos += pdfFontEmbed.Size + 10;
// layout a PdfLine object in a PDF page
PdfLine pdfLine = new PdfLine(new PointFloat(crtXPos, crtYPos), new PointFloat(crtXPos + 60, crtYPos));
page1.Layout(pdfLine);
With this layout mode you can place objects in a PDF document relative to previously placed objects in the same document. The PdfDocument class provides the following methods for relative layout of the objects:
PdfDocumentLayout(PdfObject) - Adds a PDF object after the last PDF object rendered
PdfDocumentLayout(PdfObject, Single, Single) - Adds a PDF object at the given horizontal and vertical offset after the last PDF object rendered
PdfDocumentLayout(PdfObject, Single, Boolean, Boolean, Single, Boolean, Boolean) - Adds a PDF page element to this document at the given X and Y location in the PDF page where the last element rendering ended. The location can be absolute in PDF page or relative as an offset from the position where the last element rendering ended.
Ih the following code sample the objects are positioned in a PDF document in a flow layout.
// create a PDF document
PdfDocument document = new PdfDocument(serverIP, serverPort);
// create a page in document
PdfPage page1 = document.AddPage();
float startYPos = 20;
float startXPos = 5;
#region Layout a text that expands to the right edge of the PDF page
PdfText titleTextAtLocation = new PdfText(startXPos, startYPos,
"The text below extends from the layout position to the right edge of the PDF page:", pdfFontBoldEmbed);
titleTextAtLocation.ForeColor = PdfColor.Navy;
page1.Layout(titleTextAtLocation);
PdfText textExpandsToRightEdge = new PdfText(0, 0, dummyText, pdfFont);
textExpandsToRightEdge.BackColor = PdfColor.WhiteSmoke;
document.Layout(textExpandsToRightEdge, 50, 10);
// draw a rectangle around the text
PdfRectangle borderPdfRectangle = new PdfRectangle(new RectangleFloat(0, 0, 0, 0));
borderPdfRectangle.LineStyle.LineWidth = 0.5f;
document.Layout(borderPdfRectangle);
#endregion
#region Layout a text with width limit
PdfText titleTextWithWidth = new PdfText(0, 0,
"The text below is limited by a given width and has a free height:", pdfFontBoldEmbed);
titleTextWithWidth.ForeColor = PdfColor.Navy;
document.Layout(titleTextWithWidth, startXPos, false, 10, true);
PdfText textWithWidthLimit = new PdfText(0, 0, 300, dummyText, pdfFont);
textWithWidthLimit.BackColor = PdfColor.WhiteSmoke;
document.Layout(textWithWidthLimit, 50, 10);
// draw a rectangle around the text
borderPdfRectangle = new PdfRectangle(new RectangleFloat(0, 0, 0, 0));
borderPdfRectangle.LineStyle.LineWidth = 0.5f;
document.Layout(borderPdfRectangle);
#endregion