Printing XLSX file on the printer with user-defined non-standard page size failed

Hello,

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.

Mikhael
debug screen.zip (258.1 KB)

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

@Mikhael
We will evaluate it and feedback to you soon.

@Mikhael
Please set the paper size as
Setting Page Options|Documentation .
BTW which tool creates this file? Some records are not same as generated file by MS Excel.

Hello @simon.zhao ,

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:

image.png (32.6 KB)

Mikhael

@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 sample code as follows:

PrintDocument doc = new PrintDocument();
Console.WriteLine("default: =====");
Console.WriteLine("paper height: " + doc.PrinterSettings.DefaultPageSettings.PaperSize.Height/100d);
Console.WriteLine("paper width: " + doc.PrinterSettings.DefaultPageSettings.PaperSize.Width/100d);

Workbook wb = new Workbook();
Worksheet sheet = wb.Worksheets[0];
sheet.PageSetup.PaperSize = PaperSizeType.PaperA2;
Console.WriteLine("PaperA2 :=====");
Console.WriteLine("paper height: " + sheet.PageSetup.PaperHeight);
Console.WriteLine("paper width: " + sheet.PageSetup.PaperWidth);

sheet.PageSetup.PaperSize = PaperSizeType.Custom;
Console.WriteLine("Custom :=====");
Console.WriteLine("paper height: " + sheet.PageSetup.PaperHeight);
Console.WriteLine("paper width: " + sheet.PageSetup.PaperWidth);

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

Hello @John.He,

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

@Mikhael,

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

       ...

Hello @peyton.xu,

Thank you for this advice!

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:

test code.jpg (206.9 KB)
test files.jpg (131.0 KB)
LM-QrCode-randyg-20230913015050.zip (4.9 KB)

My code snipped I used for this test is below.

Mikhael

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

@Mikhael,

Thanks for providing sample document, screenshots and details.

We will evaluate and look into it soon.

By the way, may be you should wait for your other issue (in the thread) to be sorted out first.

@Mikhael,

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 uses the lastest version Aspose.Cells for .Net 23.9.

@peyton.xu,

Thank you for this info!

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.

Mikhael

Please post your licensing queries in relevant category there. One of our sales staff members will assist you soon.

@Mikhael

I also tested it with Aspose.Cells v22.6, the page width(3.15) and height(1.97) is also OK. Adobe_PDF_Printer_with_Aspose.Cells22.6.pdf (11.4 KB)

Hello @peyton.xu,

Thank you for your excellent support!

Mikhael

@Mikhael
You are welcome.Please feel free to reach out to us if you have any further queries or comments. We’ll be happy to assist you soon.