Re: How to print multiple packing slips to file (pdf) simultaneously?
Henrik, you can do this with a bit of coding. You need to use CustPackingSlipJour table to select the packing slips you want to print, and then loop through all records and print individual packing slip reports using the SalesFormLetter class (which actually instances SalesFormLetter_PackingSlip class when constructed for packing slips).
Here's the sample code that creates PDF printouts for all packing slips for a selected date (in this exaple I used the latest date from CustPackingSlipJour table), you can adjust it to your requirements (e.g. change select criteria, use different folder for PDF files, etc.).
// Created on 11 Jan 2011 by Jovan Bulajic
static void PrintPackingSlipsToPDF(Args _args)
{
CustPackingSlipJour custPackingSlipJour;
SalesFormLetter packingSlip;
PrintJobSettings printSet;
TransDate filterDate;
Filename pdfFile;
;
// Configure printer/PDF settings
printSet = new printJobSettings();
printSet.setTarget(PrintMedium::File);
printSet.format(PrintFormat::PDF);
printSet.warnIfFileExists(false);
printSet.suppressScalingMessage(true);
printSet.setTarget(PrintMedium::File);
// Initialize the report
packingSlip = SalesFormletter::construct(DocumentStatus::PackingSlip, false);
// Select date of the latest packing slip (e.g. today - to use this for testing)
select maxOf(DeliveryDate) from custPackingSlipJour;
filterDate = custPackingSlipJour.DeliveryDate;
info(strFmt('Printing Packing Slips for %1', filterDate));
// Process all packing slips for the selected date
while select *
from custPackingSlipJour
where custPackingSlipJour.DeliveryDate == filterDate
{
// Set the PDF file name
pdfFile = strFmt('C:\\Temp\\PackingSlip_%1.pdf', custPackingSlipJour.PackingSlipId);
printSet.fileName(pdfFile);
// Print packing slip to PDF
packingSlip.updatePrinterSettingsFormLetter(printSet.packPrintJobSettings());
custPackingSlipJour.printJournal(packingSlip);
}
}