|
//Load the true type font.
Stream fontstream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("App1.Assets.arial.ttf");
//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a new page.
PdfPage page = doc.Pages.Add();
//Initialize the PDF true type font.
PdfFont font = new PdfTrueTypeFont(fontstream, 12, PdfFontStyle.Regular);
//Draw text.
page.Graphics.DrawString("hello world! @ # €", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); |
|
//Create a new PDF document.
PdfDocument document = new PdfDocument();
//Add a new PDF page.
PdfPage page = document.Pages.Add();
//Create new PdfTrueTypeFont instance.
//Load the font from assets.
Stream fontStream = typeof(App).GetTypeInfo().
Assembly.GetManifestResourceStream
("RTLDemo.Assets.arial.ttf"); PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12);
//Create a PdfStringFormat.
PdfStringFormat format = new PdfStringFormat();
//Set text direction.
format.TextDirection = PdfTextDirection.RightToLeft;
//Set text alignment.
format.Alignment = PdfTextAlignment.Right;
//Draw text to the PDF document.
page.Graphics.DrawString("بالعالم مرحبا !",font, PdfBrushes.Black, Syncfusion.Drawing.PointF.Empty, format);
//Save document.
MemoryStream ms = new MemoryStream();
document.Save(ms);
//Close the PdfDocument instance.
document.Close(true);
|
string text = "Hello world!!! Hello world!!!";
string Date = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
string ReceiptTitle = "Receipt for Payment of P.O.Box Rent";
string Branch = "Branch : Ruwi";
//Creates a new PDF document. PdfDocument doc = new PdfDocument(); //Adds a page. PdfPage page = doc.Pages.Add(); //Acquires page's graphics PdfGraphics graphics = page.Graphics; PdfStringFormat drawFormat = new PdfStringFormat(); drawFormat.WordWrap = PdfWordWrapType.Word; drawFormat.Alignment = PdfTextAlignment.Justify; drawFormat.LineAlignment = PdfVerticalAlignment.Top; //Set the font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); //Create a solid brush. PdfBrush brush = new PdfSolidBrush(new PdfColor(Syncfusion.Drawing.Color.Black)); RectangleF bounds = new RectangleF(new PointF(10, 10), new SizeF(page.Graphics.ClientSize.Width - 30, page.Graphics.ClientSize.Height - 20)); // Draw the string one after another. graphics.DrawString("??????? ????? !", font, brush, bounds, drawFormat); graphics.DrawString(Date, font, brush, new PointF(20, 10), drawFormat); graphics.DrawString(ReceiptTitle, font, brush, new PointF(100, 10), drawFormat); graphics.DrawString(Branch, font, brush, new PointF(320, 10), drawFormat); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Add values to list List<object> data1 = new List<object> Object row1 = new { English_Title = "Receipt No.", Value = "001100000008412", Arabic_Title = "??????? ????? !" }; Object row2 = new { English_Title = "Subscriber's Name", Value = "Priya test", Arabic_Title = "??????? ????? !" }; Object row3 = new { English_Title = "Post Box No", Value = "1026", Arabic_Title = "??????? ????? !" }; data1.Add(row1); data1.Add(row2); data1.Add(row3); //Add list to IEnumerable IEnumerable<object> dataTable = data1; //Assign data source. pdfGrid.DataSource = dataTable; for (int i = 0; i < data1.Count; i++) { for (int j = 0; j < 3; j++) { pdfGrid.Rows[i].Cells[j].Style.Borders.All = PdfPens.Transparent; } } //Draws PdfLightTable and returns the rendered bounds. PdfLayoutResult result1 = pdfGrid.Draw(page, new PointF(10, 40)); //draw string with returned bounds from table graphics.DrawString(text, font, brush, result1.Bounds.X, result1.Bounds.Bottom, drawFormat); //Save the PDF document to stream. MemoryStream stream = new MemoryStream(); doc.Save(stream);
//Close the document.
doc.Close(true);
//Save the stream as a file in the device and invoke it for viewing
Xamarin.Forms.DependencyService.Get
|
//Load font
Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.arial.ttf");
PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12); |
|
PdfGridCellStyle style = new PdfGridCellStyle();
style.Font = font;
style.StringFormat.TextDirection = PdfTextDirection.RightToLeft;
//Set style to grid
pdfGridCell.Style = style; |