Hi, i’m using AllColumnsInOnePagePerSheet option in my excel conversion to pdf in a stream, but i have a problem related with this option
Let’s see this code
Aspose.Cells.PdfSaveOptions OptionsC = new Aspose.Cells.PdfSaveOptions();
OptionsC.AllColumnsInOnePagePerSheet = true;
((Aspose.Cells.Workbook)m_oDocument).Save(_oOutputStream, OptionsC);
var fileStream = File.Create(“D:/test/exportPDFaspose.pdf”);
oOutputStream.Seek(0, SeekOrigin.Begin);
oOutputStream.CopyTo(fileStream);
fileStream.Close();
((Aspose.Cells.Workbook)m_oDocument).Save(“D:/test/exportPDFaspose2.pdf”);
First Pdf file saved from stream differs from the second file saved directly from Aspose to file!
The difference is manifested with OptionsC.AllColumnsInOnePagePerSheet = true;
If i comment this line the two files are the same
See attached sample files we are proofing
We need to use OptionsC.AllColumnsInOnePagePerSheet = true; in our solution but we need also to obtain stream from aspose in the same way it saves direcly into file
(we work with streams).
For instance, in our sample files, 2.xls is wrong converted in stream but is right converted in file, so we need the same conversion in stream also.
Please, let me know about this
Hi,
Thanks for your posting and using Aspose.Cells.
If you set PdfSaveOptions.AllColumnsInOnePagePerSheet as true and save your Excel file as PDF with this option on the disk, it will generate the same results as you have shown in 2_savetostream.pdf file
Please see the following code. I have attached the output pdf which is same as your 2_savetostream.pdf for your reference.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\2.xlsx”;
Workbook workbook = new Workbook(filePath);
PdfSaveOptions options = new PdfSaveOptions();
options.AllColumnsInOnePagePerSheet = true;
workbook.Save(filePath + “.out.pdf”, options);
Hi, maybe I have not explained:
if convert 1.xlsx or 2.xlsx (reading it from stream when you instantiate the aspose cells object) to pdf direcly on disk obtain a different pdf than converting same files on stream.
Can you reproduce this?
As you can see in the sampl files i provided, if I convert 2.xls on disk and on stream i obtain two different results!
The right pdf result is pdf obtained saving to disk: we need the same result saving it on a stream (and reading xls files again from a stream), we cannot present a final pdf 250px * 1400px, is a non-sense…
Why results are not the same?
It seems the problem exists (or is more visible) when excel files use few columns, if you fill some other (column B, D, F etc…)… in case of, as example, using only A column Pdf resulting from saving to disk will be about 900 px width, instead of saving to stream and obtaining a 250 px width
Hi,
Thank You
Just for clarity, for us the right page size is page size created when saving direcly on disk (For instance A4 pdf document 210 * 297 mm)
Hi,
Thanks for using Aspose.Cells.
If you want to compare difference between saving to disk and saving to
steam, you should use the same pdfSaveOptions (in your code,
saving to stream with a pdfSaveOptions, but saving to disk without it will produce different results )
We said clearly in our documents for the AllColumnsInOnePagePerSheet property:
If AllColumnsInOnePagePerSheet is true , all column content of one sheet will output to only one page in result. The width of paper size of pagesetup will be ignored, and the other settings of pagesetup will still take effect.
If you want the page size should not change and all columns are in one page. Please using the following code:
C#
foreach (Worksheet ws in wb.Worksheets)
{
ws.PageSetup.FitToPagesWide = 1;
}
wb.Save(".out.pdf");
Yes, you’re right.
But the problem is using AllColumnsInOnePagePerSheet in some cases of Excel columns, as noticed by Babar Raza opening CELLSNET-42873 issue.
There is another problem related to AllColumnsInOnePagePerSheet = true
We are testing it and we’ll open other post for it.
Hi again,
Hi again,
var m_oDocument = new Workbook(myDir + “1.xlsx”);
Aspose.Cells.PdfSaveOptions OptionsC = new Aspose.Cells.PdfSaveOptions();
OptionsC.AllColumnsInOnePagePerSheet = true;
using (var oOutputStream = new System.IO.MemoryStream())
{
((Aspose.Cells.Workbook)m_oDocument).Save(oOutputStream, OptionsC);
var fileStream = System.IO.File.Create(myDir + “stream_saved.pdf”);
oOutputStream.Seek(0, System.IO.SeekOrigin.Begin);
oOutputStream.CopyTo(fileStream);
fileStream.Close();
}
m_oDocument.Save(myDir + “disk_saved.pdf”, OptionsC);
ok We got it, and accomodate using some considerations on column number and width so we use or not AllColumnsInOnePagePerSheet parameter.
Thank’s
Hi,