I wanted to convert an excel file to a pdf. The excel file, when converted to pdf, will show each page on different pdf pages and also the fixed header in the excel file gets printed on all the pdf pages. Could you please help me how can I change the excel print settings in order to resolve this.
Please see the document on how to render one PDF page per whole Excel worksheet for your reference:
To add header on all rendered pages, you may accomplish the task using the following ways. You have to add the code as per the topics before rendering/saving to PDF file format:
If you want to add title rows/columns (in the worksheet), you may try the printing tile rows/column option(s): Rows to repeat at top/Columns to repeat at left: Page Setup and Printing Options|Documentation
Thank you for your help. I have a thing to ask… when I set the worksheet.PageSetup.FitToPagesTall property to 1 it tries to fit the complete sheet into the same page on the PDF.
I want to know is there any method in Aspose where if the sheet size is large it moves the cells after a particular number of rows to the next pdf page?
Should I try to do something with Printarea property if it overflows move the data to next page in PDF? Could you please help me with this.
Well, when you specify FitToPagesTall option to 1 (together with FitToPagesWide option to 1), it will try to render (by scaling or shrinking) all the rows and columns of the sheet in one page. If you specify FitToPagesTall option to 1 (together with FitToPagesWide option to null/0), it will not care about columns and try to render all the rows (vertically) only, so if there are lots of columns in the sheet, certain columns might be rendered in other pages.
For your needs, I think you may try inserting page breaks instead at your specified/desired location in the sheet, see the document for your reference:
This doesn’t seem to help. I want a page break after a particular interval. If a sheet has more data it should itself flow to the next page in the pdf.
Also, is there a way to hide a particular sheet in excel so that it doesn’t show up in the pdf.
Why it does not work? You can insert page breaks at your desired location (cell) as per the document example (I suggested to check). For your information, MS Excel itself puts automatic page breaks in the worksheet at regular intervals based on your worksheet data accordingly, so if the data is large, MS Excel puts different sets of data at different pages (by inserting automatic page breaks). As you need to insert your custom page breaks, so you may add horizontal/vertical page breaks at your your desired location.
Well, you may try to use Worksheet.IsVisible Boolean attribute to hide/show your desired worksheets in the workbook before rendering to PDF file format.
Setting page break may not work, if there are too many data in a page break content, it will also split to several pages.
You can try copy data to a new sheet, setting one page per sheet and then save to Pdf. Please see the following sample code, its input Excel file and its output Pdf file for a reference.
@shakeel.faiz thank you for the help. But this seems to be a little confusing i have only some of the excel worksheets where there is large data. When I do a fit to page it fits the complete sheet into one page in the pdf and I want to retain that setting but for some sheets where the data is large, the font size becomes completely invisible. So I wanted something like when the page fills in the data flows to the next page or i can iterate through the sheet and insert a page break after a regular interval. I am not having a clear idea that how should i proceed to break a particular sheet.
Please create your simple sample Excel file manually using Microsoft Excel and then also create the expected Excel file or its Pdf manually and provide it to us.
i.e.
We need the following things to look into this issue deeper.
1 - Sample Excel File
2 - Expected Output Excel File or Pdf
Please use the following code. It fits all columns in a single page but rows can take multiple pages. The code generates two pages pdf. But since, there are too many columns, so font scale is small.
If you do not want to fit all columns in a single page, then just open and save your Excel file in Pdf format.
Workbook wb = new Workbook("EXCEL.xlsx");
Worksheet ws = wb.Worksheets[0];
//Comment these two lines if you want to print like MS-Excel Print Preview
ws.PageSetup.FitToPagesWide = 1;
ws.PageSetup.FitToPagesTall = 0;
wb.Save("output.pdf");
It is good to know that you were able to sort out a part of problem. Please provide us the actual output Pdf and expected output Pdf for comparison. We will look into them and provide you sample code to achieve the expected output Pdf.
@shakeel.faiz : actually it is the table header that is getting repeated. When we split the page after the table is finished there are some notes which get diplayed on the next page in the pdf but that page has the table header on it even when the table is not there
I am afraid, I am not able to replicate the table header problem. As I requested earlier, I need your simplified input Excel file, your actual Pdf and your expected Pdf. You can create your expected Pdf manually using Microsoft Excel and Save As… Pdf option.
Without comparing the Excel file, Actual Pdf and Expected Pdf, it is not possible to resolve this issue and provide you sample code.
Please create a separate thread for this issue. However, you can group and ungroup data with these methods.
@shakeel.faiz : hi shakeel i tired to replicate it … When i do it with the normal sheet the table header is not coming on the next page if the page is divided but with my excel this is happening.
When there are so many columns in table and page size has limited width, then it is inevitable that some of the columns will move to next page.
However, when you are rendering it to Pdf, you can control the page order. You can render it in Horizontal-wise or Vertical-wise. By default, it renders vertical-wise.
The following sample code will render the worksheet Horizontal-wise. It means, it will first render entire table headings in multiple pages if needed and then it will start rendering first set of rows, then second set of rows etc.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.