插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

129 lines
4.3 KiB

package com.fanruan.api.report;
import com.fanruan.api.log.LogKit;
import com.fr.base.Margin;
import com.fr.general.DeclareRecordType;
import com.fr.log.LogUtils;
import com.fr.main.FineBook;
import com.fr.page.ClippedPageProvider;
import com.fr.page.PaperSettingProvider;
import com.fr.page.ReportPageProvider;
import com.fr.page.ReportSettingsProvider;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.cellattr.CellGUIAttr;
import com.fr.report.stable.ReportSettings;
import com.fr.stable.Constants;
import com.fr.stable.web.SessionProvider;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/9/25
* 报表打印导出相关工具类
*/
public class PrintKit {
private PrintKit() {
}
/**
* 根据模板获取打印/导出的页面设置
*
* @param book 模板
* @return 多个待打印对象的页面设置集合
*/
public static List<PaperSettingProvider> getPaperSettings(FineBook book) {
return PrintKit.getPaperSettings(book, null);
}
/**
* 根据模板获取打印/导出的页面设置
*
* @param book 模板
* @param offsetMargin 偏移量
* @return 多个待打印对象的页面设置集合
*/
public static @Nullable List<PaperSettingProvider> getPaperSettings(FineBook book, Margin offsetMargin) {
if (book == null) {
return null;
}
List<PaperSettingProvider> list = new ArrayList<>();
ReportSettingsProvider reportSettings;
for (int i = 0; i < book.getReportCount(); i++) {
reportSettings = book.getReport(i).getReportSettings();
if (reportSettings == null) {
reportSettings = ReportSettings.DEFAULTSETTINGS;
}
try {
PaperSettingProvider setting = (PaperSettingProvider) reportSettings.getPaperSetting().clone();
Margin margin = setting.getMargin();
/*
* 偏移量top、left为加,button 、right为减
*/
if (offsetMargin != null) {
margin.setTop(margin.getTop().add(offsetMargin.getTop()));
margin.setLeft(margin.getLeft().add(offsetMargin.getLeft()));
margin.setBottom(margin.getBottom().subtract(offsetMargin.getBottom()));
margin.setRight(margin.getRight().subtract(offsetMargin.getRight()));
}
list.add(setting);
} catch (CloneNotSupportedException e) {
LogKit.error(e.getMessage(), e);
break;
}
}
return list;
}
/**
* 选取分页结果对象中可导出的对象,如果没有可导出对象,会返回null。
*
* @param reportPage 分页结果对象
* @return 可导出对象
*/
public static @Nullable ClippedPageProvider pick(ReportPageProvider reportPage) {
if (reportPage == null) {
return null;
}
ClippedPageProvider[] clippers = reportPage.getPages();
if (clippers.length == 1 && clippers[0] != null) {
ClippedPageProvider cp = clippers[0];
cp.deriveResolution(Constants.FR_PAINT_RESOLUTION);
return cp;
}
return null;
}
/**
* 单元格是否可打印/导出,典型的如:以html格式显示的单元格,就是不可打印/导出的
*
* @param cell 单元格
* @return 单元格内容可打印/导出则返回true,否则返回false
*/
public static boolean isCellPrintable(CellElement cell) {
if (cell == null) {
return false;
}
CellGUIAttr gui = cell.getCellGUIAttr();
return gui == null || gui.isPrintContent();
}
/**
* 记录打印信息
*
* @param templateName 模板名
* @param parameterMap 参数
* @param printType 打印类型
* @param session 会话
*/
public static void recordPrintInformation(String templateName, Map parameterMap,
DeclareRecordType printType, SessionProvider session) {
LogUtils.recordPrintInformation(templateName, parameterMap, printType, session);
}
}