Dear Syncfusion's team,
Firstly, I wild thank you for all what you are doing for the community.
I'm beginner and I want use Pdf xamarin to generate invoices documents. However, I need help to create invoice like showed in attached file.
Best regards
Hi Gowthamraj
Thank you for your response.
I generated a pdf document. However, I have some problems, showed in attached file and I hope you help me to resolve them :
1) Overlapping table and footer !?
2) Some elements do not appear in the table. For example, the number of the last element in the first page is 18 and the next element, that has number 19 does not appear in the second page?
3) Why the blank space appears at the beginning of page 2?
Best regards
Hi Gowthamraj,
I can't resolve the problem.
Here's my code
------------------------------------------- Code Begin
// Création document PDF size A4
PdfDocument document = new PdfDocument();
document.PageSettings.Orientation = PdfPageOrientation.Landscape;
document.PageSettings.Margins.All = 20;
document.PageSettings.Size = PdfPageSize.A4;
document.PageSettings.Orientation = PdfPageOrientation.Portrait;
PdfPage page = document.Pages.Add();
PdfGraphics g = page.Graphics;
//Entete Nom de ma société
PdfTextElement element = new PdfTextElement("Entreprise Name" + "\n" + "Tel: ");
element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);
element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0));
PdfLayoutResult result = element.Draw(page, new Syncfusion.Drawing.RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200));
//Police du titre bon
PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14);
//Couleur arriere plan du titre bon
PdfColor couleurFondTitreBon = new PdfColor(230, 230, 230);
g.DrawRectangle(new PdfSolidBrush(couleurFondTitreBon), new Syncfusion.Drawing.RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30));
element = new PdfTextElement("Bon de livraison N° 1", subHeadingFont);
element.Brush = PdfBrushes.Black;
result = element.Draw(page, new Syncfusion.Drawing.PointF(10, result.Bounds.Bottom + 48));
string currentDate = "Date " + DateTime.Now.ToString("dd/MM/yyyy HH:mm");
Syncfusion.Drawing.SizeF textSize = subHeadingFont.MeasureString(currentDate);
g.DrawString(currentDate, subHeadingFont, element.Brush, new Syncfusion.Drawing.PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y));
//
//Client
element = new PdfTextElement("A ", new PdfStandardFont(PdfFontFamily.TimesRoman, 10));
element.Brush = new PdfSolidBrush((new PdfColor(0, 0, 0)));
result = element.Draw(page, new Syncfusion.Drawing.PointF(10, result.Bounds.Bottom + 25));
//Ligne horizontale
g.DrawLine(new PdfPen(new PdfColor(126, 151, 173), 0.70f), new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + 3), new Syncfusion.Drawing.PointF(g.ClientSize.Width, result.Bounds.Bottom + 3));
//Nom Client
element = new PdfTextElement("Nom Client", new PdfStandardFont(PdfFontFamily.TimesRoman, 10, PdfFontStyle.Bold));
element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));
result = element.Draw(page, new Syncfusion.Drawing.RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100));
///
/// Préparer liste des article
///
List<object> detailBon = new List<object>();
for (int i = 0; i < 400; i++)
{
detailBon.Add(new
{
N = i.ToString(),
Référence = "Référence article",
Designation = "Designation",
Quantité = "qte",
PrixHT = "PrixHT",
Remise = "RemiseP",
PrixNetHT = "PrixNetHT",
MontantHT = "MontantNetHT"
});
}
PdfGrid grid = new PdfGrid();
grid.DataSource = detailBon;// GetProductDetails(id);
//Formater Header
PdfGridRow header = grid.Headers[0];
PdfGridCellStyle headerStyle = new PdfGridCellStyle();
headerStyle.Borders.All = new PdfPen(new PdfColor(0, 0, 0)); ;// new PdfPen(new PdfColor(126, 151, 173));
headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(230, 230, 230)); ;// new PdfSolidBrush(new PdfColor(126, 151, 173));
headerStyle.TextBrush = PdfBrushes.Black; //PdfBrushes.White;
headerStyle.Font = new PdfStandardFont(PdfFontFamily.Courier, 10f, PdfFontStyle.Bold);
//Alignement text header
header.Cells[5].Value = "R %";
for (int i = 0; i < header.Cells.Count; i++)
{
if (i == 2 || i == 1)
header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
else
header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
}
header.ApplyStyle(headerStyle);
//Les lignes ROWS
PdfGridCellStyle cellStyle = new PdfGridCellStyle();
cellStyle.Borders.Top = cellStyle.Borders.Bottom = PdfPens.Transparent; //.All = PdfPens.White;
cellStyle.Borders.Left = cellStyle.Borders.Right = PdfPens.Black;
cellStyle.CellPadding = new PdfPaddings(2, 2, 2, 2);
cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0)); //new PdfSolidBrush(new PdfColor(131, 130, 136));
//La dernière ligne
PdfGridCellStyle cellStyleBottom = new PdfGridCellStyle();
cellStyleBottom.Borders.All = PdfPens.Black;
cellStyleBottom.Borders.Top = PdfPens.Transparent;
cellStyleBottom.CellPadding = new PdfPaddings(2, 2, 2, 2);
foreach (PdfGridRow row in grid.Rows)
{
row.ApplyStyle(cellStyle);
for (int i = 0; i < row.Cells.Count; i++)
{
PdfGridCell cell = row.Cells[i];
if ((i == 1) || (i == 2))
cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
else
cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
}
}
if (grid.Rows.Count > 0)
{
grid.Rows[grid.Rows.Count - 1].ApplyStyle(cellStyleBottom);
}
grid.Columns[0].Width = 20;
grid.Columns[1].Width = 60;
grid.Columns[2].Width = 160;
grid.Columns[5].Width = 30;
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
layoutFormat.Break = PdfLayoutBreakType.FitPage;
layoutFormat.Layout = PdfLayoutType.Paginate;
PdfGridLayoutResult gridResult = grid.Draw(page, new Syncfusion.Drawing.Point(0, (int)result.Bounds.Bottom + 40), layoutFormat);
#region PageNumber and footer
//Dessiner zone pied de page cette zone peut etre aussi utilisee comme en tete
Syncfusion.Drawing.RectangleF bounds = new Syncfusion.Drawing.RectangleF(0, 0, page.GetClientSize().Width, 50);
//Couleur d'ecriture
PdfColor couleurPied = new PdfColor(126, 151, 173);
//Create a Page template that can be used as footer.
PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds);
PdfFont fontPied = new PdfStandardFont(PdfFontFamily.Helvetica, 8);
PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black);
//Create page number field.
PdfPageNumberField pageNumber = new PdfPageNumberField(fontPied, brush);
//Create page count field.
PdfPageCountField count = new PdfPageCountField(fontPied, brush);
//Add the fields in composite fields.
PdfCompositeField compositeField = new PdfCompositeField(fontPied, brush, "Page {0} / {1}", pageNumber, count);
compositeField.Bounds = footer.Bounds;
//Ligne horizontale pied de page
footer.Graphics.DrawLine(new PdfPen(couleurPied, 0.70f), 0, 0, footer.Width, 0);
//Editeur Cosyspro
footer.Graphics.DrawString("Bon de livraison N° 1" +
" -- Imprimé le " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"), fontPied, PdfBrushes.Black, new Syncfusion.Drawing.RectangleF(0, 20, page.GetClientSize().Width, 50));
//Draw the composite field in footer.
compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(page.GetClientSize().Width - 80, 20));
//Add the footer template at the bottom.
document.Template.Bottom = footer;
#endregion
#region Save and open with Xamarin.Essentails
//Save the document to the stream
MemoryStream stream = new MemoryStream();
document.Save(stream);
document.Close(true);
---------------------------------------- Code End
Regards
Hi Gowthamraj,
I resolve it. Thank you for all responses
Regards