我找到了此解决方案以使文本居中对齐
string conString = "Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XX.XX)(PORT = 1521)))(CONNECT_DATA=(SID=XXX))); User Id = XXX; Password = XXX;";
using (OracleConnection con = new OracleConnection(conString))
{
using (OracleCommand cmd = con.CreateCommand())
{
try
{
con.Open();
cmd.BindByName = true;
cmd.CommandText = "select doc from archivos where rownum = 1";
OracleDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
await context.Response.WriteAsync("Datos: " + reader.GetString(0) + "\n");
}
reader.Dispose();
reader[0].ToString();
con.Close();
}
catch (Exception ex)
{
await context.Response.WriteAsync(ex.Message);
}
}
}
我可以用它来对齐中心
(function(API){
API.centerText = function(txt, options, x, y) {
options = options ||{};
/* Use the options align property to specify desired text alignment
* Param x will be ignored if desired text alignment is 'center'.
* Usage of options can easily extend the function to apply different text
* styles and sizes
*/
if( options.align == "center" ){
// Get current font size
var fontSize = this.internal.getFontSize();
// Get page width
var pageWidth = this.internal.pageSize.width;
// Get the actual text's width
/* You multiply the unit width of your string by your font size and divide
* by the internal scale factor. The division is necessary
* for the case where you use units other than 'pt' in the constructor
* of jsPDF.
*/
txtWidth = this.getStringUnitWidth(txt)*fontSize/this.internal.scaleFactor;
// Calculate text's x coordinate
x = ( pageWidth - txtWidth ) / 2;
}
// Draw text at x,y
this.text(txt,x,y);
}
})(jsPDF.API);
但是它仅适用于一行,如果文本为多行,则无效
doc.centerText('this is first line',{align: "center"},0,40);
如何对齐多条线的中心?