Skip to content

xlxs to pdf text offset  #61

@kulapika159

Description

@kulapika159

1
2
3

this problem occurred when I changed the server,The two servers have the same fonts,the original server is ok

/**
* excel 转为pdf 输出。
*
* @param sourceFilePath excel文件
* @param desFilePathd pad 输出文件目录
*/
public static void excel2pdf(String sourceFilePath, String desFilePathd) {
if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
return;
}
try {
Workbook wb = new Workbook(sourceFilePath);// 原始excel路径
// Worksheet worksheet = wb.getWorksheets().get(0);
// worksheet.getPageSetup().setPaperSize(PaperSizeType.PAPER_A_4_SMALL);
// System.out.println(worksheet.getPageSetup().getPaperSize());

        FileOutputStream fileOS = new FileOutputStream(desFilePathd);
        PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
        pdfSaveOptions.setAllColumnsInOnePagePerSheet(true);
        pdfSaveOptions.setOnePagePerSheet(false);


        int[] autoDrawSheets = {3};
        //当excel中对应的sheet页宽度太大时,在PDF中会拆断并分页。此处等比缩放。
        autoDraw(wb,autoDrawSheets);

        int[] showSheets = {0};
        //隐藏workbook中不需要的sheet页。
        printSheetPage(wb, showSheets);
        wb.save(fileOS, pdfSaveOptions);
        fileOS.flush();
        fileOS.close();
        log.info(desFilePathd + "生成完毕");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions