Đây là tốt nhất mà tôi đã đi lên với:Có cách nào tốt hơn để lấy số trang từ PrintDocument không?
public static int GetPageCount(PrintDocument printDocument)
{
printDocument.PrinterSettings.PrintFileName = Path.GetTempFileName();
printDocument.PrinterSettings.PrintToFile = true;
int count = 0;
printDocument.PrintController = new StandardPrintController();
printDocument.PrintPage += (sender, e) => count++;
printDocument.Print();
File.Delete(printDocument.PrinterSettings.PrintFileName);
return count;
}
Có cách nào tốt hơn để làm điều này? (Đây là thực tế khá chậm)
Không phải với PrintDocument riêng của mình. Bạn sẽ cần phải biết số lượng trang của tệp bạn muốn in qua số lượng dòng và lề bạn sẽ sử dụng và số lượng dòng bạn muốn trên mỗi trang, v.v. – Wildhorn