officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-translatetransform-x28-system-dot-single-system-dot-single-x29.md
Translates the coordinate system origin to the specified point.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Drawing.dll
NuGet Package : DevExpress.Pdf.Drawing
public void TranslateTransform(
float x,
float y
)
Public Sub TranslateTransform(
x As Single,
y As Single
)
| Name | Type | Description |
|---|---|---|
| x | Single |
The x-coordinate of the translation.
| | y | Single |
The y-coordinate of the translation.
|
This method multiplies the transformation matrix of the PdfGraphics object by a translation matrix. The translation matrix includes the x and y parameters.
Note
Coordinate system transformations (for example, system rotation) are not taken into account for the following methods:
the following code snippet translates the coordinate system origin and draws shapes in the initial and translated coordinate systems.
using DevExpress.Pdf;
using DevExpress.Drawing;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
processor.CreateEmptyDocument();
PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
using (PdfGraphics graphics = processor.CreateGraphicsWorldSystem())
{
var rectangle = new RectangleF(0, 0, 300, 300);
// Draw a green square.
using (var brush = new DXSolidBrush(Color.Green))
graphics.FillRectangle(brush, rectangle);
// Translate the coordinate system.
graphics.TranslateTransform(200, 400);
// Draw a blue square in the translated coordinate system.
using (var brush = new DXSolidBrush(Color.Blue))
graphics.FillRectangle(brush, rectangle);
// Add graphics content to the document page.
graphics.AddToPageForeground(page);
}
processor.SaveDocument("out2.pdf");
}
Process.Start("out.pdf");
Imports DevExpress.Pdf
Imports System.Drawing
'...
Using processor As New PdfDocumentProcessor()
processor.CreateEmptyDocument()
Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4)
Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
Dim rectangle = New RectangleF(0, 0, 300, 300)
' Draw a green square.
Using brush = New DXSolidBrush(Color.Green)
graphics.FillRectangle(brush, rectangle)
End Using
' Translate the coordinate system.
graphics.TranslateTransform(200, 400)
' Draw a blue square in the translated coordinate system.
Using brush = New DXSolidBrush(Color.Blue)
graphics.FillRectangle(brush, rectangle)
End Using
' Add graphics content to the document page.
graphics.AddToPageForeground(page)
End Using
processor.SaveDocument("out2.pdf")
End Using
Process.Start("out.pdf")
The following code snippets (auto-collected from DevExpress Examples) contain references to the TranslateTransform(Single, Single) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
pdf-document-api-add-graphics-to-landscape-and-portrait-pages/CS/CreateGraphics/Program.cs#L54
graphics.RotateTransform(-90);
graphics.TranslateTransform(-cropBoxHeight, 0);
return new SizeF(cropBoxHeight, cropBoxWidth);
pdf-document-api-generate-document-layout/CS/DocumentCreationAPI/Program.cs#L60
float scale = (float)(watermarkSize / (double)stringSize.Width);
graphics.TranslateTransform((float)(page.CropBox.Width * 0.5),(float)(page.CropBox.Height * 0.5));
graphics.RotateTransform((float)45.0);
pdf-document-api-add-graphics-to-landscape-and-portrait-pages/VB/CreateGraphics/Program.vb#L47
graphics.RotateTransform(-90)
graphics.TranslateTransform(-cropBoxHeight, 0)
Return New SizeF(cropBoxHeight, cropBoxWidth)
pdf-document-api-generate-document-layout/VB/DocumentCreationAPI/Program.vb#L61
Dim scale As Single = CSng(watermarkSize) / stringSize.Width
graphics.TranslateTransform(CSng(page.CropBox.Width * 0.5), CSng(page.CropBox.Height * 0.5))
graphics.RotateTransform(45.0)
See Also