As you can see on my code snippet below I try print a simple XLSX file on virtual printer, that let me define custom paper size. Unfortunately, Aspose.Cells printout page size is still “Letter”.
Please look an attached archive file to get XLSX file I try print and screenshot image, that shows, that I’m tryiyng to send correct page size to Aspose.Cells.
Please let me know if I should change any different settings to solve this task.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sPrinterName = “Universal Document Converter”
Dim sSrcFile = “C:\In\LM-QrCode-randyg-20230913015050.xlsx”
Try
Dim pd As New Printing.PrintDocument()
pd.PrinterSettings.PrinterName = sPrinterName
pd.PrintController = New Printing.StandardPrintController()
Dim excelDoc = New Workbook(sSrcFile, New LoadOptions(LoadFormat.Auto))
Dim ws = excelDoc.Worksheets.Item(excelDoc.Worksheets.ActiveSheetIndex)
Dim imgOptions01 As New ImageOrPrintOptions() With {
.PrintingPage = PrintingPageType.Default,
.PrintWithStatusDialog = False
}
Dim sr01 = New SheetRender(ws, imgOptions01)
sr01.ToPrinter(pd.PrinterSettings, "my test")
Catch ex As Exception
End Try
End Sub
Unfortunately, this article is about using standard page sizes like A4 or Letter. But if I open my virtual printer settings and change paper size to 80x50 mm, AsposeCells still prints on 8.27x11.69 page.
Please look at this screenshot image with variables values I highlighted:
@Mikhael,
Please run the following sample code and provide feedback on your output results. After setting the paper size to custom, we can obtain the same size.
The output as follows:
default: =====
paper height: 11.69
paper width: 8.27
PaperA2 :=====
paper height: 23.39
paper width: 16.54
Custom :=====
paper height: 11.69
paper width: 8.27
I set my virtual printer as system default. After this I called this code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim doc = New Printing.PrintDocument()
Console.WriteLine(“default: =====”)
Console.WriteLine("Printer name: " + doc.PrinterSettings.PrinterName)
Console.WriteLine("paper height: " + (doc.PrinterSettings.DefaultPageSettings.PaperSize.Height / 100D).ToString())
Console.WriteLine("paper width: " + (doc.PrinterSettings.DefaultPageSettings.PaperSize.Width / 100D).ToString())
Dim wb = New Workbook()
Dim sheet = wb.Worksheets(0)
sheet.PageSetup.PaperSize = PaperSizeType.PaperA2
Console.WriteLine("PaperA2 :=====")
Console.WriteLine("paper height: " + sheet.PageSetup.PaperHeight.ToString())
Console.WriteLine("paper width: " + sheet.PageSetup.PaperWidth.ToString())
sheet.PageSetup.PaperSize = PaperSizeType.Custom
Console.WriteLine("Custom :=====")
Console.WriteLine("paper height: " + sheet.PageSetup.PaperHeight.ToString())
Console.WriteLine("paper width: " + sheet.PageSetup.PaperWidth.ToString())
End Sub
And here is the output I see in the console window:
default: =====
Printer name: Universal Document Converter
paper height: 1,97
paper width: 3,15
PaperA2 :=====
paper height: 23,39
paper width: 16,54
Custom :=====
paper height: 11,69
paper width: 8,27
If the default paper size of your printer is your desired paper size, after setting the custom paper size to the worksheet using ws.PageSetup.CustomPaperSize(3.15, 1.97). Our render may use the default paper size of your printer.
Dim pd As New Printing.PrintDocument()
pd.PrinterSettings.PrinterName = sPrinterName
pd.PrintController = New Printing.StandardPrintController()
Dim excelDoc = New Workbook(sSrcFile, New LoadOptions(LoadFormat.Auto))
Dim ws = excelDoc.Worksheets.Item(excelDoc.Worksheets.ActiveSheetIndex)
ws.PageSetup.CustomPaperSize(3.15, 1.97)
Dim imgOptions01 As New ImageOrPrintOptions() With {
.PrintingPage = PrintingPageType.Default,
.PrintWithStatusDialog = False
...
Now the printout page size looks correct, but it seems, that something was happen with page orientation.
As you can see on “test code.jpg” I attached, printed page width should be bigger, that height. But as you can see on “test files.jpg”, output pahe height is bigger.
I used Universal Document Converter to print test page with the same page sizes, and the printout page width and height looks correctly.
You can download Universal Document Converter trial if you need it for your tests from:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sPrinterName = "Universal Document Converter"
Dim sSrcFile = "C:\In\LM-QrCode-randyg-20230913015050.xlsx"
Try
Dim pd As New Printing.PrintDocument()
pd.PrinterSettings.PrinterName = sPrinterName
pd.PrintController = New Printing.StandardPrintController()
Dim excelDoc = New Workbook(sSrcFile, New LoadOptions(LoadFormat.Auto))
Dim ws = excelDoc.Worksheets.Item(excelDoc.Worksheets.ActiveSheetIndex)
If 0 = pd.PrinterSettings.DefaultPageSettings.PaperSize.RawKind Then
ws.PageSetup.CustomPaperSize(pd.PrinterSettings.DefaultPageSettings.PaperSize.Width / 100D, pd.PrinterSettings.DefaultPageSettings.PaperSize.Height / 100D)
End If
Dim imgOptions01 As New ImageOrPrintOptions() With {
.PrintingPage = PrintingPageType.Default,
.PrintWithStatusDialog = False
}
Dim sr01 = New SheetRender(ws, imgOptions01)
sr01.ToPrinter(pd.PrinterSettings, "my test")
Catch ex As Exception
End Try
End Sub
I used “Adobe PDF” virtual printer, added a custom paper size with 3.15 * 1.97 inch as the default paper size, the result is OK.Adobe_PDF_Printer.pdf (10.5 KB)
I use Aspose.Cells version 22.6 and it seems, that my subscription for your maintance is expired.
Could you please send me a link to order an update for my subscription to Mikhael.Bolgov@gmail.com ?
I opened my file “Aspose.Cells.NET.lic” in notepad and it seems, that my order number id 211116170126. My colleague ordered this license from Europ for me using different email address.