Oracle P/L SQL实现PDF报表内容生成
Package UTL_PDF as
--文件转化为二进制流
Function f_File2Blob(
as_SubDir in VarChar2,
as_FileName in VarChar2
)Return Blob;
--不同单位换算
Function f_ConvertUnit(
an_Value in Number,
as_Unit in VarChar2
)Return Number;
--设置页面尺寸
Procedure p_SetPageSize(
an_Width in Number,
an_Height in Number,
as_Unit in VarChar2 Default 'cm'
);
--设置页面格式,A4
Procedure p_SetPageFormat(
as_Format in VarChar2 Default 'A4'
);
--设置纸张方向(横向、纵向)
Procedure p_SetPageOrientation(
as_Orientation in VarChar2 Default 'PORTRAIT'
);
--设置纸张边沿空白
Procedure p_SetMargins(
an_Top in Number Default Null,
an_Left in Number Default Null,
an_Bottom in Number Default Null,
an_Right in Number Default Null,
as_Unit in VarChar2 Default 'cm'
);
--设置页面属性信息(主题、作者、关键字)
Procedure p_SetProperty(
as_Title in VarChar2 Default Null,
as_Author in VarChar2 Default Null,
as_Subject in VarChar2 Default Null,
as_Keywords in VarChar2 Default Null
);
--初始化
Procedure p_Initial;
--取得PDF
Function f_GetPDF
Return Blob;
--保存当前生成的PDF到指定的文件名
Procedure p_SavePDF(
as_SubDir in VarChar2 Default 'FTP_DIR',
as_FileName in VarChar2 Default 'my.pdf',
ab_FreeBlob in Boolean Default True
);
--文本到页面
Procedure p_Text2Page(
as_Text in VarChar2
);
--写文本
Procedure p_PutText(
ai_X in Number,
ai_Y in Number,
as_Text in VarChar2,
ai_DegreesRotation in Number Default Null --旋转角度(用于水印)
);
--文本字符长度
Function f_StrLength(
as_Text in VarChar2
)Return Number;
--写行
Procedure p_Write(
as_Text in Clob,
ai_X in Number Default Null,
ai_Y in Number Default Null,
ai_LineHeight in Number Default Null,
ai_Start in Number Default Null, -- left side of the available text box
an_Width in Number Default Null, -- width of the available text box
as_Alignment in VarChar2 Default Null
);
--设置字体
Procedure p_SetFont(
ai_Index in PLS_Integer,
an_FontSize in Number,
ab_Output2Doc in Boolean Default True
);
--设置字体
Function f_SetFont(
as_FontName in VarChar2,
an_FontSize in Number,
ab_Output2Doc in Boolean Default True
)Return PLS_Integer;
--设置字体
Procedure p_SetFont(
as_FontName in VarChar2,
an_FontSize in Number,
ab_Output2Doc in Boolean Default True
);
--设置字体
Function f_SetFont(
as_Family in VarChar2,
as_Style in VarChar2 Default 'N',
an_FontSize in Number Default Null,
ab_Output2Doc in Boolean Default True
)Return PLS_Integer;
--设置字体
Procedure p_SetFont(
as_Family in VarChar2,
as_Style in VarChar2 Default 'N',
an_FontSize in Number Default Null,
ab_Output2Doc in Boolean Default True
);
--新增一页
Procedure p_NewPage;
--装载矢量字体(True Type)
Function f_LoadFont_TTF(
ab_FontTTF in Blob,
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True,
ai_Offset in Number Default 1
)Return PLS_Integer;
--装载矢量字体(True Type)
Procedure p_LoadFont_TTF(
ab_FontTTF in Blob,
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True,
ai_Offset in Number Default 1
);
--装载矢量字体(True Type)
Function f_LoadFont_TTF(
as_SubDir in VarChar2 Default 'FTP_DIR',
as_FontName in VarChar2 Default 'BAUHS93.TTF',
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True
)Return PLS_Integer;
--装载矢量字体(True Type)
Procedure p_LoadFont_TTF(
as_SubDir in VarChar2 Default 'FTP_DIR',
as_FontName in VarChar2 Default 'BAUHS93.TTF',
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True
);
--装载矢量字体(True Type)
--.ttc是microsoft开发的新一代字体格式标准, TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体
Procedure p_LoadFont_TTC(
ab_FontTTC in Blob,
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True
);
--装载矢量字体(True Type)
--.ttc是microsoft开发的新一代字体格式标准, TTC是几个TTF合成的字库,安装后字体列表中会看到两个以上的字体
Procedure p_LoadFont_TTC(
as_SubDir in VarChar2 Default 'FTP_DIR',
as_FontName in VarChar2 Default 'CAMBRIA.TTC',
as_Encoding in VarChar2 Default 'WINDOWS-1252',
ab_Embed in Boolean Default False,
ab_Compress in Boolean Default True
);
--设置字体前景色
Procedure p_SetColor(
as_RGB in VarChar2 Default '000000'
);
--设置字体前景色
Procedure p_SetColor(
an_Red in Number Default 0,
an_Green in Number Default 0,
an_Blue in Number Default 0
);
--设置背景色
Procedure p_SetbgColor(
as_RGB in VarChar2 Default 'ffffff'
);
--设置背景色
Procedure p_SetbgColor(
an_Red in Number Default 0,
an_Green in Number Default 0,
an_Blue in Number Default 0
);
--画水平线
Procedure p_HorizontalLine(
ai_X in Number,
ai_Y in Number,
an_Width in Number,
an_LineWidth in Number Default 0.5,
as_LineColor in VarChar2 Default '000000'
);
--画垂直线
Procedure p_VerticalLine(
ai_X in Number,
ai_Y in Number,
an_Height in Number,
an_LineWidth in Number Default 0.5,
as_LineColor in VarChar2 Default '000000'
);
--画矩阵
Procedure p_Rectangle(
ai_X in Number,
ai_Y in Number,
an_Width in Number,
an_Height in Number,
as_LineColor in VarChar2 Default Null,
as_FillColor in VarChar2 Default Null,
an_LineWidth in Number Default 0.5
);
Function f_Get(
ai_What in PLS_Integer
)Return Number;
--写图片(二进制流)
Procedure p_PutImage(
ab_Image in Blob,
ai_X in Number,
ai_Y in Number,
an_Width in Number Default Null,
an_Height in Number Default Null,
as_Alignment in VarChar2 Default 'center',
as_VerAlign in VarChar2 Default 'top'
);
--写图片(图片文件)
Procedure p_PutImage(
as_SubDir in VarChar2,
as_FileName in VarChar2,
ai_X in Number,
ai_Y in Number,
an_Width in Number Default Null,
an_Height in Number Default Null,
as_Alignment in VarChar2 Default 'center',
as_VerAlign in VarChar2 Default 'top'
);
--写图片(网页地址)
Procedure p_PutImage(
as_URL in VarChar2,
ai_X in Number,
ai_Y in Number,
an_Width in Number Default Null,
an_Height in Number Default Null,
as_Alignment in VarChar2 Default 'center',
as_VerAlign in VarChar2 Default 'top'
);
--设置页眉、页脚内容
Procedure p_SetPageProc(
as_PageProc in VarChar2,
ab_SameAllPages in Boolean Default True --True作为页眉、页脚,每页一样
);
Type tn_ColumnWidths is Table of Number;
Type ts_Headers is Table of VarChar2(32767);
Procedure p_Query2Table(
as_QuerySQL in VarChar2,
atn_Widths in tn_ColumnWidths Default Null,
ats_Headers in ts_Headers Default Null
);
$IF not DBMS_DB_VERSION.VER_LE_10 $Then
Procedure p_refCursor2Table(
ac_rc sys_refCursor,
atn_Widths tn_ColumnWidths Default Null,
ats_Headers ts_Headers Default Null
);
$End
E