Gembox Spreadsheet - Remove blank pages - c#

I dont know how achieve this, I have to create an informative report with images. For this, I use an excell template (It helps me with the format and with the position of the text where to place the respective information). The images are generated perfectly. I convert this XLS to PDF with the property
DocumentToMemoryStream (excelTemplate, XlsxSaveOptions.XlsxDefault);
This report generate blank pages in the PDF. How can I remove these blank pages, before the excel is generated?

Without checking your spreadsheet it's impossible to tell from where do those empty pages come from, so can you upload your XLS?
Anyway, do you perhaps have some explicitly defined horizontal or vertical page breaks?
If yes, can you remove the ones you don't need?
Or, do you perhaps have empty columns at the end which have some kind of styling or formatting?
If yes, then you could try using something like this to remove those empty columns from exporting to PDF:
var workbook = ExcelFile.Load("input.xls");
var worksheet = workbook.Worksheets.ActiveWorksheet;
worksheet.NamedRanges.SetPrintArea(
worksheet.GetUsedCellRange(true));
var options = new PdfSaveOptions();
options.SelectionType = SelectionType.ActiveSheet;
workbook.Save("output.pdf", options);

I had a counter of the rows of the document I was writing on, thanks to the help of #Mario Z, I use this function, before the save and solve my problem of blank pages
wsimgs.NamedRanges.SetPrintArea(wsimgs.Cells.GetSubrange("A1",CellRange.RowColumnToPosition (countRow, 10)));

Related

Acrobat DC SDK: Replace checkbox with texbox

Am trying to achieve certain PDF automation with Acrobat SDK. So far, with the help of examples, I was able to update fillable PDF forms programmatically. However, I am now facing a scenario where I need to number these fillable fields sequentially.
This is easy in case of text fields which accept string values. However, I cannot do the same with checkboxes or radiobuttons etc as they are expecting certain predefined values to make them check/un-check.
ItextSharp has PdfCanvas class which has BeginText method write text on a rectangular bounding box.
Do we have something similar in Adobe?. I have the cordinates from GetRect() method
see code below:
CAcroApp acroApp = new AcroAppClass();
CAcroAVDoc avDoc = new AcroAVDocClass();
CAcroPDDoc pDDoc = new AcroPDDocClass();
CAcroPDPage pDPage;
CAcroPDAnnot pDAnnot;
avDoc.Open("Fillable PDF", "");
pDDoc = (CAcroPDDoc)avDoc.GetPDDoc();// gets PDDoc from AVDoc
pDPage = (CAcroPDPage)pDDoc.AcquirePage(0);// gets the 1st page
pDAnnot = (CAcroPDAnnot)pDPage.GetAnnot(8);// Index 8 is checkbox
var x = pDAnnot.GetRect();// holds the left,right,top,bottom value
Since I couldn't find anything similar for inserting text into checkbox, I was thinking of using an alternate approach where I remove the checkbox from the PDF using RemoveAnnot() method and adding a textbox at the same position.
pDPage = (CAcroPDPage)pDDoc.AcquirePage(0)
pDPage.RemoveAnnot(8);// this removes the fillable checkbox and leaves a square figure in PDF
Now, Any idea on how can I add a textbox in same position?
Or in general, Is it possible to change the field type from checkBox to textbox ?
There are little to no examples on "Creating Fillable forms programmatically with Acrobat SDK"
Any suggestion or guidance will greatly help me .

Getting the number of rows PER PAGE in Excel using C#

I stated the question above the way I did, because I can already do the following, and it doesn't give me the solution I need.
I can:
Get the number of pages per sheet
Get the last USED row on any given SHEET (not per printed page, so that doesn't help)
I can find out if manual or automatic page breaks have been inserted
(just not WHERE)
And that's what I need: To know the number of the row for each page break on any given sheet. Some sheets have 1 page, some have 100.
I need to do this because I need to put something at the bottom of each page, however, the number of pages per sheet is not static. Some sheets have been set to landscape, others to portrait. Some sheets have the "Put all columns on one page" option set, which CHANGES the number of rows on that page.
PLEASE NOTE: The solution to this problem is not "Use the footer", as the footer will not accept the data that I need to put on each page.
I also cannot statically decide the number of rows each page type might have -- I let Excel decide that when I set the orientation.
I've been looking for several days now, and I have been unable to find how to determine what the last row on a printed page will be.
I'm using office and VS 2010 and I'm using the office interop. I'm not posting much code because I have no idea what to use at this point. However, it is safe to say that to access any given worksheet I'm using the following code:
Excel.Application excelApp = new Excel.Application();
Excel.Worksheet workSheet;
I'd be willing to bet that there's a very simple way to do this, and I just haven't hit across the right combination of google search terms. But it's been a few days now, so I thought I'd post something here. Thanks for any help.
I don't think you have a way to calculate that on your own... It is very complicated, because the number of rows on each page depends on many variables (Printer page size, orientation, zoom level, etc.).
You can try to use this: Repeat specific rows or columns on every printed page

Writing content in cells of excel using excel object is viewed in c#.net

I am going to write the content to the cells of an excel template using excel object in c#.net.
I have no problem in writing in the cells of the excel it works fine, but while writing the content in the cells of the excel, i can able to view the content writing in the cells.
But I need to restrict not view this action.
Can any one give me an idea about how to resolve this issue?
Please let me know if this is not clear.
If you are asking to hide screen updating, try:
xlApp.ScreenUpdating = false;
At the end, don't forget to turn it back on:
xlApp.ScreenUpdating = true;
Some of the answers to this question may help as well.

Jumping to the next page in iTextSharp PdfPtable when creating one for a PdfPDocument document

I'm building up an iTextSharp PdfPTable object that will later be passed to Document.Add() to be populated to a PDF file.
I'm going crazy over trying to figure out how to jump to the next page. Can anyone advise how to format the table and make the text start at what will appear to be the next page once populated to a DPF document ?
Thanks in advance!
Found two solutions:
1) Re-creating a new table, triggering document.NewPage() and document.Add() every time I had to jump to a new page.
2) Implementing a custom PDFdWriter PageEvent on the pdfWriter.PageEvent property.

iTextSharp read pdf template from hard drive and write text

I have a basic PDF file that I has 5 different blank content areas that I want to use iTextSharp to write text too. The problem is I'm not sure the best way to accomplish this. I have attempted to use ColumnText to accomplish this, but I cannot seem to add multiple ColumnText objects.
ColumnText tagColumn = new ColumnText(pdfContentByte);
tagColumn.SetSimpleColumn(460, 100, 620, 160);
string[] tagColors = bt.DealerTagColor.Split('|');
Font tagFont = FontFactory.GetFont(bt.DealerTagFont, bt.DealerTagSize, Font.NORMAL, new BaseColor(int.Parse(tagColors[0]), int.Parse(tagColors[1]), int.Parse(tagColors[2])));
Paragraph p = new Paragraph(dto.Tag, tagFont);
p.Leading = bt.DealerTagSize;
tagColumn.AddElement(p);
tagColumn.Go();
What I like about the ColumnText is it allows me to essential define a heigth/width, and position of the text area.
Any thoughts on how I can accomplish this with or without using ColumnText? I just need to have control of the font/fontsize/font color/leading/and width of the area which will allow the text to wrap.
The easiest way would be to create and use form fields on your template PDF. This way you can reference a form field by name and set its value with a simple function call.
This article helped me:
Fill in PDF Form Fields using the Open Source iTextSharp Dynamic Link Library
EDIT: PdfPTables?
If your ColumnTexts are tabularly arranged consider using a PdfPTable. I've used PdfPTables to fill rows of data in forms generated from a blank template form. You need to figure out the x-coordinate of each of your columns and use these values when adding PdfPCells to your table, but it does work. I've never had to set an upper limit to the height of a PdfPCell but I image you can do it.
Check this page for more on PdfPTables.

Categories