Selecting a different papersource in aspose.cells

We aren’t able to print on a different papersource in Aspose.Cells. Is there a way to do this. We tried the following code:

Private sr As SheetRender

Private pd As New PrintDocument

Private Sub ToPrinter(ByVal Tray As PaperSource)

Dim book As Workbook = New Workbook("test.xlsx")

Dim io As New ImageOrPrintOptions

io.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff

pd.PrinterSettings.PrinterName = cboprinter.SelectedItem

For Each _ps As PaperSource In pd.PrinterSettings.PaperSources

If _ps.RawKind = Tray.RawKind Then

pd.DefaultPageSettings.PaperSource = _ps

End If

Next

Dim pe As New PrintPageEventHandler(AddressOf PrintPage)

'Dim qe As New QueryPageSettingsEventHandler(AddressOf QueryPage)

io.CustomPrintPageEventHandler = pe

'io.CustomQueryPageSettingsHandler = pe

sr = New SheetRender(book.Worksheets(0), io)

sr.ToPrinter(cboprinter.SelectedItem)

End Sub

'Private Sub QueryPage(ByVal sender As Object, ByVal ev As QueryPageSettingsEventArgs)

' ev.PageSettings.PaperSource = pd.DefaultPageSettings.PaperSource

'End Sub

Private Sub PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs)

ev.PageSettings.PaperSource = pd.DefaultPageSettings.PaperSource

sr.CustomPrint(False, ev)

ev.HasMorePages = False

End Sub

But I think it should be in the queryPageSettings handler instead of the printPage. Problem is that we can’t add a handler to this queryPageSettings.

We tried everything, we do it now with the aspose.pdf.facade, but it takes very long and the quality isn’t good enough.
Does someone knows a solution?

Hi Bart,

Thanks for considering Aspose.Cells.

It seems your issue is not related with Aspose.Cells. Could you elaborate your issue more? It will help us look into your issue more closely and we will be able to help you asap.

Hi,

Thanks for your reply.

The issues is certainly related to Aspose.Cells. We are trying to print a worksheet to a printer with different papersources (trays). for example: sheet 1 from workbook 1 to tray 1, sheet 1 from workbook 2 to bypass tray, ...

For this we were using the ImageOrPrintOptions class of the aspose.cells.rendering namespace and the sheetrender.toprinter function. This code we get from an old topic (293308). But this is not working. For this reason we have created some additional functions to save the (excel) cells document to a pdf and print the pdf on the tray. This is working, but the quality is poor and the printing time is too high for our customer.

In our tests we tried the print a printdocument of the .net framework with setting the papersource in the PrintPage method with the same result (not working). But if we place it in the QueryPageSettings handler it works perfectly. This handler is not available in the ImageOrPrintOptions class of aspose.cells. (This code we added in comment in the example above)

Hi Bart,

Thanks for your posting and using Aspose.Cells.

You cannot change the paper source in .NET Framework as we requested you to provide demo project earlier in this post. However, we have logged your issue in our database for investigation. We will look into it and if possible implement this feature. Once, we will have some fix or update for you, we will let you know asap.

This issue has been logged as CELLSNET-42063.

Hello,

is this something for the near future or could this take several months? Just because a customer is complaining about the printing speed and we need to find a solution. Otherwise we will have to look for an other possibility.
Attached a demo project where we are able to print a printdocument in .net to different papersources.
thanks in advance.

Hi Bart,

Thank you for sharing your sample project. I have attached it to the ticket (CELLSNET-42063) already associated with this thread.

Regarding the status of the ticket, I am afraid; it is pending for analysis, and therefore we can not share a estimated release schedule for this feature (if applicable). Please spare us little time to properly analyze the problem, and to check the feasibility for its implementation. As soon as we have any updates in this regard, we will share here for your reference.

Thank you for your patience and cooperation.

Hi Bart,

Thanks for using Aspose.Cells.

Please use the following code for your needs.

C#


SheetRender sr;

ImageOrPrintOptions io;

//Init



PrintPageEventHandler pe = new PrintPageEventHandler(PrintPage);

io.CustomPrintPageEventHandler = pe;

sr.ToPrinter(yourPrinter);


// The PrintPage event is raised for each page to be printed.

void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)

{

//set paper source

ev.PageSettings.PaperSource = …

int currentIndex = sr.CustomPrint(true, ev);

if (currentIndex != sr.PageCount)

ev.HasMorePages = true;

else ev.HasMorePages = false;

}

Hi,

Thanks for your reply.

As we described above, the provided code is not working. If we print with this code the printer is taking the paper from the default tray.<span style=“font-size:10.0pt;font-family:“Courier New”;color:blue;
mso-ansi-language:EN-US;mso-no-proof:yes” lang=“EN-US”>

private<span style=“font-size:10.0pt;font-family:“Courier New”;mso-ansi-language:EN-US;
mso-no-proof:yes” lang=“EN-US”> void PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ev)

{

//set paper source

ev.PageSettings.PaperSource = _TempPrintDocument.DefaultPageSettings.PaperSource;

int currentIndex = _SheetRender.CustomPrint(true, ev);

if (currentIndex != _SheetRender.PageCount)

{

ev.HasMorePages = true;

}

else

{

ev.HasMorePages = false;

}

}

_PrintDocument.PrinterSettings.DefaultPageSettings.PaperSource = (PaperSource)cbops1.SelectedItem;

...

private void _PrintDocument_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)

{

e.PageSettings.PaperSource = _PrintDocument.PrinterSettings.DefaultPageSettings.PaperSource;

}

private void _PrintDocument_PrintPage(Object sender, System.Drawing.Printing.PrintPageEventArgs e)

{

e.Graphics.DrawString("test", this.Font, Brushes.Black, 100, 100);

e.HasMorePages = false;

}

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>After adding this handler, the printing is done correctly.

Hi Bart,

Thanks for your posting and using Aspose.Cells.

We have logged your feedback and comments in our database for investigation. We will look into it and see if we could meet your requirements. Once, we will have some update for you, we will let you know asap.

Hi,


Please try our latest version/fix: Aspose.Cells for .NET v7.5.3.6 , we have fixed your issue.

We have add the property: CustomQueryPageSettingsEventHandler in class “ImageOrPrintOptions” for your needs.<o:p></o:p>


Let us know your feedback.

Thanks,

The issues you have found earlier (filed as CELLSNET-42063) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Thanks for the discussion; it helped me to resolve this this issue. Just wanted to post my solution in case it helps someone else solve this issue:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Printing;
using Aspose.Cells;
using Aspose.Cells.Rendering;

namespace AsposePrint
{
public partial class Form1 : Form
{
private string printerName;
private string tray;
private string filename;
private short copies;

private SheetRender sheetRender;
private PrintDocument printDocument = new PrintDocument();
private PaperSource paperSource;

public Form1()
{
InitializeComponent();
}

public Form1(string printerName, string tray, string filename, string copies)
{
InitializeComponent();

this.printerName = printerName;
this.tray = tray;
this.filename = filename;
if (short.TryParse(copies, out this.copies) == false) this.copies = 1;
}

protected override void OnShown(EventArgs e)
{
base.OnShown(e);

Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(“Aspose.Cells.lic”);

ImageOrPrintOptions io = new ImageOrPrintOptions();
PrintPageEventHandler pe = new PrintPageEventHandler(pd_PrintPage);
QueryPageSettingsEventHandler qe = new QueryPageSettingsEventHandler(pd_QueryPageSettings);

io.CustomPrintPageEventHandler = pe;
io.CustomQueryPageSettingsEventHandler = qe;

printDocument.PrinterSettings.PrinterName = printerName;
printDocument.PrinterSettings.Copies = copies;

try
{
paperSource = printDocument.PrinterSettings.DefaultPageSettings.PaperSource;
}
catch
{
this.Close();
return;
}

foreach (PaperSource ps in printDocument.PrinterSettings.PaperSources)
{
if (ps.SourceName == tray) paperSource = ps;
}

try
{
Workbook workbook = new Workbook(filename);
Worksheet worksheet = workbook.Worksheets[0];

sheetRender = new SheetRender(worksheet, io);

sheetRender.ToPrinter(printerName);
}
catch
{
this.Close();
return;
}

this.Close();

}

private void pd_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
{
e.PageSettings.PaperSource = paperSource;
}

private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{

int currentIndex = sheetRender.CustomPrint(true, e);

if (currentIndex != sheetRender.PageCount)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
}
}

Hi Larry,


Thank you for sharing the solution here for Aspose community. Please feel free to contact us in case you need our assistance with Aspose APIs.