I am maintaining an application which can receive a particular PDF loaded with PDF digital drop downs and extract the selections from it. It will then input this into the database. The system works fine, but we also have a small console application that generates the particular PDF file, which we use in case the PDF needs to change.
An issue has been flagged up with the dropdown boxes. The dropdowns will usually host very long answers to questions and ideally, these should be wrapped so they are easily readable. Instead, the current generated PDF does not wrap but instead shows the selection on one line, which results in the text size fluctuating between dropdowns, with some being insanely small and difficult to read.
My question is - is there a way in iTextSharp to wrap the text shown within the drop downs? I tried googling it but I did not receive any answers relating to iText in general but for Acrobat.
Now this is where I think this question becomes futile. We want to wrap the text without using line breaks, so that the input method on the other side doesn't misconstrue the answers.
We are using iTextSharp 5.5.0 to generate the PDF, and the EasyPDF proprietary package to read off from the PDF. I can't provide screenshots of the PDF for confidentiality reasons, but please let me know if my description is not helpful and I will generate an example of what I am talking about.
The below code is a snippet from a switch that controls the drop down creation.
AddTextCell(table, question.Qno);
AddTextCell(table, question.Text, 1, 2);
cell = new PdfPCell
{
CellEvent = new ChoiceFields(
question.Id.ToString(),
question.PossibleAnswers.Select(x => x.Text).ToList(),
question.PossibleAnswers.Select(x => x.Id.ToString()).ToList(),
0)
};
cell.MinimumHeight = 15f;
cell.Colspan = 3;
cell.HorizontalAlignment = 1;
cell.NoWrap = false;
table.AddCell(cell);
Related
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 .
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)));
I have a requirment is to export data from DB table to Excel. I'm using MVC project where from View the user click a button to call a controller action to perform the export opertaion. The DB proc returns rows where couple of columns contains HTML data like
<ul><li>Name1</li><li>Name2</li></ul>
and this should be shown in Excel cell as below
Name1Name2
How can i do this ? any kind of help is deeply appreciated.
To recap the comments:
In general it's not possible to apply any styling via code (VBA or C#) that cannot be applied through the Excel interface.
Styling possibilities in Excel are quire limited, you can set font properties (size, weight, font, etc) by character, but 'paragraph' formatting can only be set per cell if at all.
Things that can be set per cell are alignment and indent (and text wrapping)
In order to simulate the bullet list, you could use VBA code like this:
Cells(1, 1).Value = Chr(149) & " foo" & vbCrLf & Chr(149) & " bar"
Cells(1, 1).IndentLevel = 2
C# code would be very similar.
But this is as good as it gets, doing anything more complicated in a single cell is unfortunately not possible. If you have to use Excel, I suggest you have just single paragraph per cell.
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.
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.