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 .
Related
Is there a way to insert captions to image just like MS word allows you to insert caption when right clicking an image? The problem is the existing caption support differs with the right-click method in a way that the figure number is not updated. I want to do it in the exact same way such that figure number is also appended with the caption by itself.
After doing research for about 2 days I found a way myself to insert Caption in Word exactly like "Insert Caption" option when we right click an image or a table.
Actually in MS Word the figure or table numbers are Document Fields. Yes that might sound a bit new but these field are there and can be viewed by right clicking any inserted caption in the document and clicking Toggle Field Codes. One can say these are actually formulas that represent different meaning. For instance the {SEQ} means initializing a sequence that starts from 1.
Ok that was enough on what actually is caption. In short we need to insert a "Document Field" with a formula to insert caption to images.
Actually this can be implemented in Xceed Opensource library by using the Simple Fields. Simple Fields are a exact replica of Document fields. And the Xceed examples uses simple for the implementation of adding page number to the document in its HeaderFooter example.
I have implemented my function that is similar to the AppendPageNumber(PageNumberFormat pnf) function.
You can use this for the implementation of captions in the Paragraph.cs
public Paragraph InsertNumberedSequence()
{
XElement fldSimple = new XElement( XName.Get( "fldSimple", Document.w.NamespaceName ) );
fldSimple.Add( new XAttribute( XName.Get( "instr", Document.w.NamespaceName ), #"SEQ " ) );
XElement content = XElement.Parse
(
#"<w:r w:rsidR='001D0226' xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"">
<w:rPr>
<w:noProof />
</w:rPr>
<w:t>1</w:t>
</w:r>"
);
fldSimple.Add( content );
Xml.Add( fldSimple );
return this;
}
And for adding caption one can use
document.InsertParagraph($"captionLabel ").InsertNumberedSequence().Append(" my caption text");
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 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);
My word file containing list of paragraphs and images and shapes.Here, Some pictures(images) are grouped itself. And each group having one text box control with some text.The Shapes are also having the text i mentioned above.
Using Microsoft.Office.Interop.Word.Paragraphs, i can able to get the paragraph text.But Could not able to get the those text.How can i get it.
In Open Xml representation, All text are inside the <w:p>.
Please guide me to get out of this issue...
Saravanan.P
You can use of "HasText" property for this to work.
if (FileDocument.Shapes.Range(1).TextFrame.HasText != 0)
{
Fieldstring.Add(FileDocument.Shapes.Range(1).TextFrame.TextRange.Text.ToString());
}
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.