Business Central – 在打印时预览时,打印机名称为空字符串

huangapple go评论73阅读模式
英文:

Business Central - Previewing when printing gives printername as empty string

问题

在进入Business Central销售发票页面时,您可以打印发票,然后会出现以下弹出窗口:

Business Central – 在打印时预览时,打印机名称为空字符串

在这里,您可以在打印机下拉菜单中选择打印机,然后我们在OnBeforeMergeDocument事件中捕获打印机名称,将其作为参数提供给您。

问题是,只有当您按下图像中底部的打印按钮时才起作用,如果您按预览,它将提供一个空字符串。

我需要在两种情况下都获取打印机名称,是否有可能在预览时获取打印机名称?

英文:

When going to the sales invoices page in business central, you can print an invoice and you will get the following popup:

Business Central – 在打印时预览时,打印机名称为空字符串

Here you can select a printer in the printer dropdown, we then catch that printer name in the OnBeforeMergeDocument event, which gives you the printername as an argument.

The problem is, this only works when you press the print button at the bottom of the popup in the image, if you press preview, it will give you an empty string.

I need the printername in both situations, is it possible to get the printername when previewing?

答案1

得分: 1

显然,在OnBeforeMergeDocument中不可能实现。这个事件是从一个名为MergeWordLayout的过程触发的,有点奇怪。它的参数中没有打印机名称。

MergeWordLayout(ReportID: Integer; ReportAction: Option SaveAsPdf,SaveAsWord,SaveAsExcel,Preview,Print,SaveAsHtml; InStrXmlData: InStream; FileName: Text; var DocumentStream: OutStream)

但是如果所选操作是“Print”,它会在调用事件之前将文件名分配给打印机名称。

if ReportAction = ReportAction::Print then
    PrinterName := FileName;

所以我会假设打印机名称实际上是通过FileName参数传递给该过程的。
无论如何,这段代码现在已经过时。我不知道您使用的BC版本是哪个,但在版本20中,OnBeforeMergeDocument被替换为OnCustomDocumentMerger,而后者又在v.21中被OnCustomDocumentMergerEx替换。
后者在ObjectPayload对象中包含打印机信息。

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-oncustomdocumentmergerex-event

英文:

Apparently it's not possible in OnBeforeMergeDocument. This event is raised from a procedure MergeWordLayout which is a bit weird. It does not have the printer name in its parameters.

MergeWordLayout(ReportID: Integer; ReportAction: Option SaveAsPdf,SaveAsWord,SaveAsExcel,Preview,Print,SaveAsHtml; InStrXmlData: InStream; FileName: Text; var DocumentStream: OutStream)

But it assigns the file name to the printer name before calling the event if the selected action is "Print".

        if ReportAction = ReportAction::Print then
            PrinterName := FileName;

So I would assume that the printer name is actually passed to the procedure in the FileName parameter.
Anyway, this code is obsolete now. I don't know which version of BC you are using, but OnBeforeMergeDocument is replaced with 'OnCustomDocumentMerger' in version 20, and this one is in its turn replaced by OnCustomDocumentMergerEx in v.21.
The latter has the printer info in the ObjectPayload object.

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-oncustomdocumentmergerex-event

huangapple
  • 本文由 发表于 2023年1月9日 18:32:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055979.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定