使用syncfusion pdf Creator时如何在PDF中显示可变数据?

问题描述 投票:0回答:1

我正在构建一个针对 Chrome 的 Flutter Web 应用程序,需要构建 PDF,因此我使用 SyncFusion 的 Flutter PDF 包

问题是我无法获取变量数据来显示我创建的 PDF 报告中。你能帮我吗?

这是我的代码:(没有错误或警告)

Future<void> createHoursReportPdf(DateTime reportDate) async {

int yearWeek = getYearWeekNumber(widget.selectedDate);
String reportTitle = "Hours Report for $yearWeek";
print(reportTitle);

// Create a PDF document.
PdfDocument document = PdfDocument();

// Add a page and draw text
document.pages.add().graphics.drawString(
    reportTitle,
    PdfStandardFont(PdfFontFamily.helvetica, 20),
    brush: PdfSolidBrush(PdfColor(0, 0, 0)),
    bounds: const Rect.fromLTWH(20, 60, 150, 30));

// Save the document
List<int> bytes = await document.save();

// Dispose the document
document.dispose();

// Download the output file - Requires import 'dart:html';
AnchorElement(
    href:
    "data:application/octet-stream;charset=utf-16le;base64,${base64.encode(bytes)}")
  ..setAttribute("download", "output_$yearWeek.pdf")    // I wonder if there's a way to just display
  ..click();

}

控制台输出为:

Hours Report for 202405

然后它创建一个 PDF,但该 PDF 不包含 $yearWeek 变量数据。它只说:“工作时间报告”。看图:

为什么此代码不包含控制台中的“202405”?

document.pages.add().graphics.drawString(
    reportTitle

谢谢您的帮助!

注意:这是一个有状态的小部件页面。我可以让这样的东西在无状态小部件中工作。

flutter pdf syncfusion
1个回答
0
投票

界限就是问题,

bounds: const Rect.fromLTWH(20, 60, 150, 300));

React.fromLTWH 表示左、上、宽、高。您没有足够的空间来显示所有文本。因为你的身高是150。

© www.soinside.com 2019 - 2024. All rights reserved.