We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

XLS to PDF issue in WPF example if Desktop resolution is 200%

Hello,

I have simple WPF application I created in MS Visual Studio 2017 as a test to convert XLSX to PDF.

This example works fine if my Desktop resolution is 100%. But In case if I chane Desktop resolution to 200% (because I have 4K monitor), output PDF file looks poor.

In attached ZIP file you can see source XLS file, PDF files I created with 200% resolution and 100% resolution. My test project is also an attachment.

So, my question is: what should I do to let my WPF applications work with any Desktop resolution value? Because the same code works well if I put it into Windows Forms Application I creave in the sane VS.

aspose cells resolution issue.zip (2.0 MB)

Mikhael

@Mikhael,

Please note, for rendering features (e.g. Excel to PDF, Sheet to image, etc.), Aspose.Cells only supports to render in 100% display settings. In other display settings, you might not get proper/perfect results.

You may specify the DPI at the start of your program in code for your requirements:
e.g.
Sample code:

.......
CellsHelper.DPI = 96 'This should be first line and before your actual code and it will be equal to 100% display settings of your os/machine. 
'........
'your code goes here.
'.......

Using the above line will ensure to get the same results (for output PDF/image) as you could generate (Save as PDF) in “100%” display settings.

Hope, this helps a bit.

Hello,

Unfortunately, this trick doesn’t help. Please look at “+96 dpi line.png” file I attached to see my example code with “CellsHelper.DPI = 96” I added.

+96 dpi line.png (188.0 KB)

Do you have any more advices for me?

Mikhael

@Mikhael,

We will check it further and get back to you soon.

@Mikhael

I test youred shared project on a 125% resolution Desktop env with CellsHelper.DPI = 96 set on the same place as your screenshot highlighted, it works OK.

Please try to log CellsHelper.DPI after you set CellsHelper.DPI = 96 to see whether CellsHelper.DPI is set successfully on your 200% resolution Desktop env.

Hello,

It seems, that “CellsHelper.DPI = 96” was ignored!

Please look at attached screenshot image fore details.
unable to change DPI.png (151.7 KB)

I can use TeamViewer to let you see my test project behavior on my computer if this can help us solve the issue we have.

Mikhael

@Mikhael

CellsHelper.DPI is only allowed to be set once. Please don’t add CellsHelper.DPI in watch window. It may be init before you set it in Debug model.
Please try to log it(e.g. log to a file) after you set CellsHelper.DPI = 96, and directly run the project(Start Without Debugging).

It works now! Thank you!!!

Mikhael

@Mikhael,

Good to know that it works for your needs now. In the event of further queries or issue, feel free to write us back.

@Mikhael,

Please notice, I am able to reproduce the issue as you mentioned by using your sample code with your template file. I found printing Excel file renders two pages instead of one page. I have logged a ticket with an id “CELLSNET-50063” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Great! I’ll wait for your message then.

Mikhael

@Mikhael,

Sure, we will keep you posted with any updates (once available) on it.

@Mikhael

The issue is fixed in the fix v21.12.2.

Aspose.Cells21.12.2 For .Net4.0.Zip (5.6 MB)
Aspose.Cells21.12.2 For .Net2_AuthenticodeSigned.Zip (5.6 MB)
Aspose.Cells21.12.2 For .NetStandard20.Zip (5.6 MB)

Thank you very much!

@Mikhael,

You are welcome.

Hello!

I have one more question for you today.

I’d like to define duplex mode, copies number and print job name. Unfortunately, defining print job name doesn’t work. My code snippet is below.

Cold you please tell me how can I solve this task?

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SetLicense()

    Dim sSrcFile = "D:\fGI Proekts -- Mike version\Code Examples\VB solutions\Aspose.Cells test\1Master.xlsx"
    Dim sPrinterName = "Canon iR C3000 Series UFR II" ' "Microsoft Print to PDF"

    Try
        Using excelDoc = New Workbook(sSrcFile)
            Dim ro As New Rendering.ImageOrPrintOptions() With {
                .PrintingPage = PrintingPageType.Default,
                .PageIndex = 1, ' start from 2-nd page
                .PageCount = 2, ' and print pages 2 and 3
                .PrintWithStatusDialog = False
            }

            Dim activeSheet = excelDoc.Worksheets(excelDoc.Worksheets.ActiveSheetIndex)
            Dim sr = New Rendering.SheetRender(activeSheet, ro)

            Dim ps As New Printing.PrinterSettings() With {
                .PrinterName = sPrinterName,
                .PrintFileName = GetFileNameExt(sSrcFile),
                .Copies = 2,
                .Collate = True,
                .Duplex = Printing.Duplex.Vertical
            }

            sr.ToPrinter(ps) ' Unable to define Print Job name here, as in this call: sr.ToPrinter(sPrinterName, GetFileNameExt(sSrcFile))

        End Using
    Catch ex As Exception
        Console.WriteLine("Unable to process '" + sSrcFile + "'. Exception: " + ex.Message)
    End Try
End Sub

@Mikhael,

We will check it but your issue/query does not seem to be related to Aspose.Cells APIs. I think you should browse internet and find respective forums for assistance.

Hm…

I have two code snippets I use to call Aspose.Cells.

  1. I can use this code to define print job name:
    sr.ToPrinter(sPrinterName, GetFileNameExt(sSrcFile))

But this code cannot be used to define duplex mode or copies quantity.

  1. This code let me define duplex and copies number, but I have no idea how to use it to define print job name:

         Dim ps As New Printing.PrinterSettings() With {
             .PrinterName = sPrinterName,
             .PrintFileName = GetFileNameExt(sSrcFile),
             .Copies = 2,
             .Collate = True,
             .Duplex = Printing.Duplex.Vertical
         }
    
         sr.ToPrinter(ps)
    

So, I guess, that 2-nd code snippet also should be able to define print job name…

In any case I’ll wait for your advice.

Mikhael

@Mikhael,

We will evaluate it and get back to you soon.

@Mikhael

We will add new API SheetRender.ToPrinter(PrinterSettings PrinterSettings, string jobName) .
I have logged a ticket with an id “CELLSNET-50088” for this feature.

Once we have an update on it, we will let you know.