英文:
Business Central - Previewing when printing gives printername as empty string
问题
在进入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:
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对象中包含打印机信息。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论