public static FPdf GetSample() { var pdf = new FPdf(); pdf.AddPage(PageSizeEnum.A4); pdf.SetFont("Arial", "", 16); pdf.Cell(40, 10, "Hello World!"); return pdf; }
public static FPdf GetSample() { var pdf = new FPdf(); pdf.AddPage(PageSizeEnum.A4); pdf.SetFont("Arial", "", 16); pdf.Cell(40, 10, "Hello World!"); return(pdf); }
public static FPdf GetSample(string filePath) { using (var pdf = new FPdf(filePath)) { pdf.AddPage(PageSizeEnum.A4); pdf.SetFont("Arial", "", 16); pdf.Cell(40, 10, "Hello World!"); return(pdf.Close()); } }
public static FPdf MeasureThenPrintRow( this FPdf pdf, TableRow row, Func <double, bool> beforePrint, params Func <TableCell, string>[] texts) { var maxHeight = MeasureRow(pdf, row, texts); var print = beforePrint?.Invoke(maxHeight) ?? true; if (!print) { return(pdf); } var maxCol = Math.Min(texts.Length, row.Cells.Count); for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; col.Status = StatusEnum.Draw; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.SavePos(); var text = texts[pos]?.Invoke(col); pdf.GoBack(); string oldStyle = null; if (col.Bold && !pdf.FontStyle.Contains("B")) { oldStyle = pdf.FontStyle; pdf.SetFont("", pdf.FontStyle + "B"); } pdf.BoxedText(col.Width, col.CellHeight ?? row.CellHeight, maxHeight, text, row.Border ?? col.Border, 0, col.Align, col.Fill); if (oldStyle != null) { pdf.SetFont("", oldStyle); } } for (var pos = maxCol; pos < row.Cells.Count; pos++) { var col = row.Cells[pos]; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.BoxedText(col.Width, col.CellHeight ?? row.CellHeight, maxHeight, " ", row.Border ?? col.Border, 0, col.Align, col.Fill); } pdf.Ln(); return(pdf); }
public void GenerateArial() { var font2 = LoadFont("Calligrapher", Path.Combine(GetPath(), "CALLIGRA.TTF")); using (var pdf = new FPdf("samplefont.pdf")) { pdf.AddPage(PageSizeEnum.A4); //pdf.SetFont("Arial", "", 16); pdf.AddFont("Calligrapher", "", "file:///" + font2.FontFile); //pdf.SetFont("AR HERMANN", "", 16); pdf.Cell(40, 10, "Enjoy new fonts with FPDF!"); pdf.Close(); } }
public static FPdf PaintRow(this FPdf pdf, TableRow row, params string[] texts) { var maxCol = Math.Min(texts.Length, row.Cells.Count); var maxHeight = row.MaxHeight; if (!texts.Any()) { maxHeight = pdf.CellMeasure(pdf.CurrentPageSize.Width, row.CellHeight, " "); } for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; var height = pdf.CellMeasure(col.Width, row.CellHeight, texts[pos]); if (maxHeight < height) { maxHeight = height; } } for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.BoxedText(col.Width, row.CellHeight, maxHeight, texts[pos], row.Border ?? col.Border, 0, col.Align, col.Fill); } for (var pos = maxCol; pos < row.Cells.Count; pos++) { var col = row.Cells[pos]; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.BoxedText(col.Width, row.CellHeight, maxHeight, " ", row.Border ?? col.Border, 0, col.Align, col.Fill); } pdf.Ln(); return(pdf); }
private static double MeasureRow(this FPdf pdf, TableRow row, Func <TableCell, string>[] texts) { var maxHeight = row.MaxHeight; var maxCol = Math.Min(texts.Length, row.Cells.Count); if (!texts.Any()) { maxHeight = pdf.CellMeasure(pdf.CurrentPageSize.Width, row.CellHeight, " "); } for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; col.Status = StatusEnum.Measure; var text = texts[pos]?.Invoke(col); string oldStyle = null; if (col.Bold && !pdf.FontStyle.Contains("B")) { oldStyle = pdf.FontStyle; pdf.SetFont("", pdf.FontStyle + "B"); } var height = pdf.CellMeasure(col.Width, col.CellHeight ?? row.CellHeight, text); if (oldStyle != null) { pdf.SetFont("", oldStyle); } if (maxHeight < height) { maxHeight = height; } } return(maxHeight); }
public static TableRow PrintRow2(this TableRow row, FPdf pdf, params Func <TableCell, string>[] texts) { pdf.PrintRow2(row, texts); return(row); }
public static string GetAnnotOptFromJsProp(this FPdf document, JsOptions prop, string colors, bool rtl = false) { var opt = new JsOptions2(); switch (prop.Alignment) { case AlignEnum.Left: opt.q = 0; break; case AlignEnum.Right: opt.q = 2; break; case AlignEnum.Center: opt.q = 1; break; case AlignEnum.Justified: throw new NotSupportedException("Justified is not supported"); break; case AlignEnum.Default: default: opt.q = rtl ? 0 : 2; break; } double lineWidth; if (prop.LineWidth.HasValue) { lineWidth = prop.LineWidth.Value; } else { lineWidth = 1; } switch (prop.BorderStyle) { case BorderStyle.None: break; case BorderStyle.Dashed: break; case BorderStyle.Beveled: break; case BorderStyle.Inset: break; case BorderStyle.Underline: break; case BorderStyle.Solid: break; default: throw new ArgumentOutOfRangeException(); } opt.Border = new double { }; return(string.Empty); }
public static FPdf PrintRow2(this FPdf pdf, TableRow row, params Func <TableCell, string>[] texts) { var maxCol = Math.Min(texts.Length, row.Cells.Count); var maxHeight = row.MaxHeight; if (!texts.Any()) { maxHeight = pdf.CellMeasure(pdf.CurrentPageSize.Width, row.CellHeight, " "); } for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; col.Status = StatusEnum.Measure; var text = texts[pos]?.Invoke(col); string oldStyle = null; if (col.Bold && !pdf.FontStyle.Contains("B")) { oldStyle = pdf.FontStyle; pdf.SetFont("", pdf.FontStyle + "B"); } var height = pdf.CellMeasure(col.Width, col.CellHeight ?? row.CellHeight, text); if (oldStyle != null) { pdf.SetFont("", oldStyle); } if (maxHeight < height) { maxHeight = height; } } for (var pos = 0; pos < maxCol; pos++) { var col = row.Cells[pos]; col.Status = StatusEnum.Draw; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.SavePos(); var text = texts[pos]?.Invoke(col); pdf.GoBack(); string oldStyle = null; if (col.Bold && !pdf.FontStyle.Contains("B")) { oldStyle = pdf.FontStyle; pdf.SetFont("", pdf.FontStyle + "B"); } pdf.BoxedText(col.Width, col.CellHeight ?? row.CellHeight, maxHeight, text, row.Border ?? col.Border, 0, col.Align, col.Fill); if (oldStyle != null) { pdf.SetFont("", oldStyle); } } for (var pos = maxCol; pos < row.Cells.Count; pos++) { var col = row.Cells[pos]; if (col.Fill) { pdf.SetFillColor(col.Background); } pdf.BoxedText(col.Width, col.CellHeight ?? row.CellHeight, maxHeight, " ", row.Border ?? col.Border, 0, col.Align, col.Fill); } pdf.Ln(); return(pdf); }
public static string Output(this FPdf document, string name, OutputDevice destination) { // Output PDF to some destination if (document.State < 3) { document.Close(); } if (destination == OutputDevice.Default) { if (string.IsNullOrEmpty(name)) { name = "doc.pdf"; destination = OutputDevice.StandardOutput; } else { destination = OutputDevice.SaveToFile; } } switch (destination) { case OutputDevice.StandardOutput: HttpContext.Current.Response.AppendHeader("Content-Type: application/pdf", ""); HttpContext.Current.Response.AppendHeader("Content-Disposition: inline; filename=\"" + name + "\"", ""); HttpContext.Current.Response.AppendHeader("Cache-Control: private, max-age=0, must-revalidate", ""); HttpContext.Current.Response.AppendHeader("Pragma: public", ""); HttpContext.Current.Response.Write(document.Buffer); break; case OutputDevice.Download: // Download file HttpContext.Current.Response.AppendHeader("Content-Type: application/x-download", ""); HttpContext.Current.Response.AppendHeader( "Content-Disposition: attachment; filename=\"" + name + "\"", ""); HttpContext.Current.Response.AppendHeader("Cache-Control: private, max-age=0, must-revalidate", ""); HttpContext.Current.Response.AppendHeader("Pragma: public", ""); HttpContext.Current.Response.Write(document.Buffer); break; case OutputDevice.SaveToFile: // Save to local file FileStream f = FileSystemSupport.FileOpen(name, "wb"); if (!TypeSupport.ToBoolean(f)) { throw new InvalidOperationException("Unable to create output file: " + name); } var writer = new StreamWriter(f, FPdf.PrivateEncoding); writer.Write(document.Buffer); writer.Close(); break; case OutputDevice.ReturnAsString: return(document.Buffer); default: throw new InvalidOperationException("Incorrect output destination: " + destination); break; } return(string.Empty); }