Converting documents using Aspose.Pdf

I know that we can do conversion using aspose.Cells and Aspose. but is it possible to convert Word and Excel document simply by using Aspose.Pdf? The Aspose.Pdf has Save() method which takes a stream, if i just change the file extension and call save() with output stream will it work?

Aspose.Pdf can do the Text file conversion as it says here http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/converting-text-file-to-pdf.html i was wondring if i can use the same approach for word and excel?

Hi,

Thanks for your interest in our products.

The Text file contains simple plain text and it does not include any special formatting information and Tags that describe the behavior of the document. If you open the Word or Excel worksheet in NotePad (or any other text editor) you will notice lots of formatting tags that describe the formatting be display of the PDF file. I am afraid Aspose.Pdf might not be able to convert Word and Excel files into PDF format. You need to use Aspose.Words to convert Word documents into PDF format and you need to use Aspose.Cells to convert Excel worksheets into PDF format.

In the event of any further query, please feel free to contact.

Thanks for th reply. I have one more question though. I tried converting Excel to PDF using Aspose.cells. It converts fine but it splits certain number of columns and put them on to different pages. So if the excel file has 10 columns, then the converted pdf has first 5 columns and the rows and then remaining 5 columns and the rows.

How do you handle such senarios and put all the columns together? Can you shrink the font size and landscape it?

Hi,

As the query is related to Aspose.Cells, so I will be moving it Aspose.Cells forum where I believe our team of experts taking care of this product would be in better position to answer this question. Please be patient and spare us little time. We apologize for your inconvenience.

Hi,


I am a representative of Aspose.Cells team. For your need we recommend you to fit the worksheet to 1 page’s height & width before saving to PDF file:
e.g

PageSetup ps = workbook.Worksheets[0].PageSetup;
ps.FitToPagesTall = 1;
ps.FitToPagesWide = 1;

See the other options available for PageSetup dialog that you may use, see the document for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-page-options.html

Also, check the article for other option that you may use:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/render-one-pdf-page-per-excel-worksheet-excel-to-pdf-conversion.html


Thank you.

the example given at the provided link does not show how the ImageOrPrintOptions assigns back to worksheet.

//Initialize a new Workbook

//Open an excel file

Workbook workbook = new Workbook("f:\\test\\Mybook.xls");

//Implement one page per worksheet option

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.OnePagePerSheet = true;

imgOptions.SaveFormat = SaveFormat.Pdf;

//Save the pdf file

workbook.Save("f:\\test\\OutputFile.pdf");

Hi,


Well, you do not need to assign the ImageOrPrintOptions options, it will be done automatically (implicitly) as you only need to specify/set the SaveFormat attribute (to set to i.e. SaveFormat.Pdf) of it.

If you find any issue with the output PDF file regarding the example code, let us know with the input and output files.

Thank you.

I think im still not getting it. We set the SaveFormat property of the ImageOption

imgOptions.SaveFormat = SaveFormat.Pdf;

And then there is no association between instance of workbook and instance of ImageOrPrintOptions, So how workbook instance knows which imgOption to use?

Hi,


Please attach your input Excel file, output Pdf file and paste your sample code here. We will check your issue soon.

Also, which version of the product you are using?

Thank you.

i'm just confused in deciding which option should i use. Should i use FitToPagesTall,FitToPagesWide option or
ImageOrPrintOption? and if i use ImageOrPrintOption how the ImageOrPrintOption works?

//this code is not working, it only generates blank PDF
            Aspose.Cells.Workbook document = new Aspose.Cells.Workbook(inputStream);
            Aspose.Cells.Rendering.ImageOrPrintOptions imgOptions = new Aspose.Cells.Rendering.ImageOrPrintOptions();
            imgOptions.OnePagePerSheet = true;
            imgOptions.SaveFormat = Aspose.Cells.SaveFormat.Pdf;
            document.Save(outputStream, Aspose.Cells.SaveFormat.Pdf);
 
//this seems to be working, Is this correct code??
            Aspose.Cells.Workbook document = new Aspose.Cells.Workbook(inputStream);
            foreach (Aspose.Cells.Worksheet ws in document.Worksheets)
            {
                ws.PageSetup.FitToPagesTall = 0;
                ws.PageSetup.FitToPagesWide = 1;
            }
            document.Save(outputStream, Aspose.Cells.SaveFormat.Pdf);

Hi,

The second code snippet is correct.

ImageOrPrintOptions has nothing to do with creating pdf. It is used for rendering images.

I have written a code example to explain to you what Worksheet.PageSetup.FitToPagesWide. Please see the output pdf and the comments, it will explain everything.

C#


string path = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


//Open the source workbook

Workbook workbook = new Workbook(path);


//Access a worksheet

Worksheet worksheet = workbook.Worksheets[0];


//Span the width of worksheet in 3 pages.

worksheet.PageSetup.FitToPagesWide = 3;

workbook.Save(path + “.3page.pdf”, SaveFormat.Pdf);


//Span the width of worksheet in 2 pages.

worksheet.PageSetup.FitToPagesWide = 2;

workbook.Save(path + “.2page.pdf”, SaveFormat.Pdf);


//Span the width of worksheet in 1 page.

worksheet.PageSetup.FitToPagesWide = 1;

workbook.Save(path + “.1page.pdf”, SaveFormat.Pdf);

Hi,


Sorry for the confusion.

Please use the following sample code and change your code as following:

Sample code:
e.g

Workbook workbook = new Workbook(“e:\test\book1.xls”);

//Implement one page per worksheet option
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.OnePagePerSheet = true;

//Save the pdf file
workbook.Save(“e:\test2\dfdfdOutputFile.pdf”, pdfSaveOptions);

I will update the related article accordingly too.

Thank you.