Not all fields showing in PDF when using Eclipse and itextpdf - java

I am using Eclipse to get data from the DB and populate a PDF. I created a form and named the fields. Everything was working fine before my computer crashed and I lost my code. I had to revert back to an older version of my code. I updated my code to populate some new fields that were added on the PDF before my computer crashed. Those new fields won't show the data.
I know the problem is not within getting the data from the DB because I can populate an older field with the new data.
My first thought is that I have to initialize the new fields but I don't know where I would do that. I did a search for a field that is showing but I only saw my code where I populate that field.
QDOB1 is an older field and is populated on the PDF.
dp.mdf("QDOB1", sChildren[1]);
QCHILD1 is a new field and won't populate.
dp.mdf("QCHILD1", sChildren[0]);
I can use sChildren[0] to populate the QDOB1 field.
dp.mdf("QDOB1", sChildren[0]);
Here is my code for dp.mdf which populates the field on the PDF.
public void mdf(String uk, String vl)
{
if ((vl != "") && (vl.trim().length() != 0))
{
AcroFields af = this.ps.getAcroFields();
try
{
af.setField(uk, vl);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, e.toString());
System.exit(0);
}
catch (DocumentException e)
{
JOptionPane.showMessageDialog(null, e.toString());
System.exit(0);
}
}
}
Do the fields on the PDF need to be initialized? If so, where do I find the file that does this? I can't find an XML file attached to this project.

I realized the form field names are case sensitive. It now works.

Related

FileUtils.copyURLToFile Getting Stuck

I'm using a Jave program to get NSE share price data from NSE's website like this for example:
url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR071122.zip");
f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f);
} catch (Exception e) {
}
The above code works for dates where market data exists, like 07/11/22 . However, where data does not exist, like on 08/11/22, the url is broken and the copyURLToFile line gets stuck indefinitely during runtime (replacing 071122 with 081122 in the url/code above will cause it to get stuck). Is there an easy way to get the program to recognize that the url for a certain date is broken (eg. https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip) and therefore ignore and continue past the try block without getting stuck?
My current workaround is to check whether a certain date is a market holiday using a DayOfWeek check as well as a HashSet containing a list of public holidays, but this is not perfect.
So, basically your URL is returning 500 error upon requesting for invalid date. You can simply use the another method available in FileUtils
https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html#copyURLToFile(java.net.URL,%20java.io.File,%20int,%20int)
Example code : (Adjust timeouts as per your requirement)
var url = new URL("https://archives.nseindia.com/archives/equities/bhavcopy/pr/PR081122.zip");
var f = new File("NSEData.zip");
try {
FileUtils.copyURLToFile(url, f, 5000, 5000);
} catch (Exception e) {
}

How to get a input field's title using PDFBox

I want to get all fields from pdf file and get all required data: field type, id, default value, title, popup text and so on.
I can get almost all data except title. If I got it right, correct field titles I can find in the pdf content chapter, but how I can match them to fields?
I use this code to get fields information.
try(PDDocument document = Loader.loadPDF(pdfFileBinary)) {
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
if (acroForm == null) {
return Collections.emptyList();
}
return acroForm.getFields()
.stream()
.flatMap(unfoldFunction)
.map(PdfFieldImpl::new)
.collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException("Can't parse pdf document");
}
If someone know the solution but with different library, it would be also great.
Sorry if it is too stupid question for you :)

SceneBuilder JavaFX using a Textbox, create a new line as per comma, from data received

I am building a tradebot, and I created my own UI. I gather data about my account via the API, and setText into a text field (as image shows). What I want to do, is be able to create a new line using the commas as a break, or be able to make some sort of excel table to separate the data and make it easy to use.
When I call for the data, it just dumps everything into a long, line of text.
Any suggestions on how to achieve this?
thanks,
Arthur
#FXML
void onPositionClick(ActionEvent event)
{
Context ctx = new Context("https://api-fxpractice.oanda.com", "XXXXXXXXXXXXXXXXXXXXXX-YYYYYYYYYYYYYYYYYYYYYYYY");
try
{
AccountSummary summary = ctx.account.summary(
new AccountID("101-XXX-XXXXXX-XXX")).getAccount();
String summaryString = String.valueOf(summary);
displayResults.setText(summaryString);
} //end try
catch (Exception e)
{
e.printStackTrace();
}//end catch
I would use System.lineSeparator() because its system-dependent:
String text = "abc,de,fghi,jklmn,o";
String newText = text.replaceAll(",", System.lineSeparator());
System.out.println(newText);
Output:
abc
de
fghi
jklmn
o

How to fill data in the table when using xml datasource in jasper reports using java?

I tried finding the solutions but I could not find any,and even some of my tables are not visible in the report. When designing the report using iReport GUI designer and filling the data using Java.
I have taken jrxml file from following location and and have taken an xml data source
try {
JRXmlDataSource jrxmlds = new JRXmlDataSource("D:\\Bhvika\\InputData11.xml","/xdata/rows/row");
Map params = new HashMap();
params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
JasperPrint print = JasperFillManager.fillReport("D:\\Bhvika\\jasperRpt3Mod11.jasper", params,jrxmlds);
JasperExportManager.exportReportToPdfFile(print, "D:\\Bhvika\\jasperRpt3Mod11.pdf");
JasperViewer.viewReport(print);
} catch (JRException e) {
e.printStackTrace();
}
By doing this i am getting a report where every field is getting populated but in the table there no value is coming.

Printing values of attribute in android

This question may sound similar ,but non of the previous questions have been helpful to me.
In my app there are 2 activities,and 5 .java classes.
I need to know the value of an attribute which is there in the dependent classes (parking.java) (not in Main_Activity).
Till time i have tried putting
System.out.println ,Log.d/e/v/i ,but nothing seems to print my value.
what ever operations I tried,I did only in that particular class.(parking.java)
Also I have set debuggable =true in manifest file.
why the values are not getting printed ,am I putting them in wrong place ? ,or something else needs to be done
Please help
Here is the code
public void setLongitude(String Longitude){
try
{
ExifInterface exif = new ExifInterface(sd.toString());
_longitude=getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE);
Log.e("Tagname","_longitude");
}
catch(IOException e)
{
e.printStackTrace();
}
}
i have put Tagname as "Nihar"
still no success,
This is the change I have made ,
try
{
ExifInterface exif = new ExifInterface(sd.toString());
_longitude=getExifTag(exif,ExifInterface.TAG_GPS_LONGITUDE);
Log.v("Tagname",_longitude);
}
catch(IOException e)
{
e.printStackTrace();
}
Here is the image

Categories