iText 7.1, C# - How to set table width to span the entire page? - itext

I'm using iText 7(.1) with C#. I have a table with data. I want the table to take up the full width. How do I do that?
The example code in the jumpstart tutorial, that is:
var table = new Table(new float[]{4, 1, 3, 4, 3, 3, 3, 3, 1});
table.SetWidthPercent(100);
doesn't quite work for some reason -- Visual Studio will complain that Table doesn't contain a definition for SetWidthPercent().

You should use:
table.SetWidth(UnitValue.createPercentValue(100));
The setWidthPercent() method is the method, you'd use in iText 7.0, but this changed in 7.1.

Related

Figure numbering; section numbering within a subsection

I have an article class document in Latex.
I want the figure numbering to just be counting within the section. 1.1, 1.2, 1.3 etc. for figures within subsection and not 1.1.1, 1.2.1, 1.2.2,...
I tried
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\counterwithin{figure}{section}
\renewcommand{\thefigure}{\arabic{subsection}.\arabic{figure}}
\counterwithin{figure}{subsection}
and just
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\counterwithin{figure}{section}
but then the figure count reset so it becomes 2.1, 2.1, 2.2, for every new subsection.
Thanks

Jasperreports: how to set axis interval?

I've got a simple task at hand: to plot integer-integer value pairs using line chart or XY chart or whatever using bean type of datasource. The bean in question returns long value both for X and Y axis. The default behavior one would expect is to show ticks of 1, 2, 3, 4, etc. on both axis.
But no, I get values like 2.5 or 1E1 for the same application running on two different machines! OK, this old post suggests to set tickLabelMask to "#". Now integers are indeed displayed, but with repeating values, like 0, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, etc. The same post suggests I add two properties to my report,
net.sf.jasperreports.chart.domain.axis.tick.interval
net.sf.jasperreports.chart.range.axis.tick.interval
Unfortunately, these have no effect when added at report level in JRXML file. When I try to add them at chart level between <reportElement ..> tags, Jaspersoft Studio removes them once I save the file. So, I take it , something has changed.
So, how could I fix this issue?
I'm using Jaspersoft Studio 6.9.0 and Jasperreports 6.6.0
Nowadays it's done using "Chart customizers". General info can be found here. To put it short, in design view select the chart, go to Properties window, select "Chart" there, scroll down to "Chart customizers" section, click "Add", and the choose range and tick customizer.
Additional artifact must be included into your project: jasperreports-chart-customizers

Filling existing pdf text fields using iText

I have a pdf document already created with some textfields.I can fill those text fields using Adobe reader and save those values with that file.
My problem is ,can i do that programmatically using iText?If it is possible ,please tell me where i can find some examples?
That's explained in the iText 7 Jump-start tutorial, more specifically in chapter 4:
This form:
Can be filled out like this:
PdfDocument pdf =
new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.getAcroForm(pdf, true);
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("name").setValue("James Bond");
fields.get("language").setValue("English");
fields.get("experience1").setValue("Off");
fields.get("experience2").setValue("Yes");
fields.get("experience3").setValue("Yes");
fields.get("shift").setValue("Any");
fields.get("info").setValue("I was 38 years old when I became an MI6 agent.");
// form.flattenFields();
pdf.close();
The result looks like this:
If you uncomment the line form.flattenFields(); then you get this:
When the form is flattened, the fields are removed, and only the content is left.
If by any chance the PDF is a dynamic XFA form, then you should provide an XML stream, and you should read the FAQ: How to fill out a pdf file programmatically? (Dynamic XFA)
As you seem to be new to iText, it is assumed that you'll use the latest version of iText (which is iText 7) as opposed to a version that is being phased out (iText 5) or obsolete (all versions prior to iText 2). However, if for any reason you choose to use iText 5, then your question is a duplicate of How to fill out a pdf file programatically? (in which case your question should be closed as a duplicate).

How do I generate multiple pages Box [1,2,3...] of [X]

I have a box label form and it all works great but we would like to be able to automatically generate sequential box labels. So on the form we would have a [Total Boxes] form field. If the user put in "5" then on the labels we would generate a different label for each box e.g. 1 of 5, 2 of 5, 3 of 5, 4 of 5, 5 of 5. I would be happy with this happening at the time they are printed, or generating a new PDF with all the pages. Either way this needs to be a very simple process for the end user of the forms. Any ideas?
I never found a perfect solution to this in Acrobat. I decided to simply recreate the form in Excel and lock the sheet except for the fields needed and then it was easy to create multiple pages.

Alter the page numbers on a pdf created with PdfSharp/Itextsharp

I am using PdfSharp/Itextsharp to stitch together a number of documents and stamp a page number at the bottom of each page. The first document in the package is the Table of Contents and is not paginated. I start the pagination with the first page after ToC. The problem is the page number that is displayed on the document is not the same as the page number indicated by the Adobe Reader.
I checked with other documents and it looks like pdf supports the option to somehow reset the page number so page 1 can start again later in the document.
How can I do this with pdfsharp or itextsharp?
The page numbers shown in Adobe Reader are defined by "Page Labels".
For instance: you number the TOC with i, ii, iii, iv, v and so on. The real page numbers are 1, 2, 3, 4, 5, and so on.
Here's a Java example from my book that shows how to work with Page Labels: http://itextpdf.com/examples/iia.php?id=234 [archived] It should be very easy to adapt it for use in C#.
If not, look for the corresponding example on this site: http://kuujinbo.info/iTextInAction2Ed/index.aspx