iTextSharp - The PDF does not display foreign characters - winforms

I have Form 3, where the Textbox and label are written with the characters "ěščřžýáíé" and that when creating a PDF in iTextSharp (finished PDF file)
does not display the desired characters "ěščřžýáíé", the space is empty. If it is listed in English, it works perfectly.
Please, how to edit the code to be able to "read" both Label and Textbox correctly.
I have now changed the label to Textbox, but I do not know how to do it to display the characters "ěščřžýáíé" and create PDF including characters ..
cod sample:
using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "PDF file|*.pdf", ValidateNames = true })
{
if (sfd.ShowDialog() == DialogResult.OK)
{
iTextSharp.text.Document doc = new iTextSharp.text.Document (PageSize.A4.Rotate());
try
{
PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
doc.Open();
doc.Add(new iTextSharp.text.Paragraph(textBox4.Text));
doc.Add(new iTextSharp.text.Paragraph(cisloTextBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox5.Text));
doc.Add(new iTextSharp.text.Paragraph(prijmeniComboBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox6.Text));
doc.Add(new iTextSharp.text.Paragraph(zaznamTextBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox7.Text));
doc.Add(new iTextSharp.text.Paragraph(poznamkaTextBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox10.Text));
doc.Add(new iTextSharp.text.Paragraph(telefonTextBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox9.Text));
doc.Add(new iTextSharp.text.Paragraph(emailTextBox.Text));
doc.Add(new iTextSharp.text.Paragraph(textBox8.Text));
doc.Add(new iTextSharp.text.Paragraph(oznameniComboBox.Text));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
doc.Close();
}
}
}
}

Related

FileChooser on iOS is not opening file (picture)

I noticed when I use a FileChooser class in order to get an image, it works on Android but not on iOS.
I suppose it might be happening because of different work of filepath or special permissions for iOS.
Any ideas/suggestions?
Thank you.
Here is my code:
ActionListener callback = e -> {
if (e != null && e.getSource() != null) {
String filePath = (String) e.getSource();
cont.removeAll();
try {
Image originImg = Image.createImage(filePath);
Image smallImg = originImg.scaled(getWidth()/2, -1);
ScaleImageButton iv = new ScaleImageButton(smallImg);
iv.addActionListener(evt->{
Dialog previewForm = new Dialog();
previewForm.addPointerReleasedListener(i-> previewForm.dispose());
ImageViewer imagePreview = new ImageViewer();
imagePreview.addPointerReleasedListener(i-> previewForm.dispose());
imagePreview.setImage(originImg.scaled(getWidth(), -1));
previewForm.setDisposeWhenPointerOutOfBounds(true);
previewForm.add(imagePreview);
previewForm.show();
});
cont.add(iv);
revalidate();
} catch (IOException ex) {
}
}
};
if (FileChooser.isAvailable()) {
Log.p("FileChooser open");
FileChooser.showOpenDialog(".png,image/png,.jpg,image/jpg,.jpeg", callback);
} else {
Display.getInstance().openGallery(callback, Display.GALLERY_IMAGE);
}
If you're using the FileChooser cn1lib notice you need to make changes to the provisioning profile. See this: https://github.com/shannah/cn1-filechooser/wiki/iOS-Setup

How to save excel file from fron-end with angularJS

i have a rest api with spring boot that works fine it uploads an excel file in temporary file then it adds it to the database
However i am a beginner in angular Js so i am not able to do that even after a long search on the internet i will appreciate any help
here is my code for the rest API
#RestController
public class UploadController {
#Autowired
PosteDao posteDao ;
//Save the uploaded file to this folder
private static String UPLOADED_FOLDER = "C://Temp//";
#PostMapping("/doUploadFile") // //new annotation since 4.3
public String singleFileUpload(#RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
if (file.isEmpty()) {
redirectAttributes.addFlashAttribute("message", "Please select a file to upload");
return "redirect:uploadStatus";
}
try {
// Get the file and save it somewhere
byte[] bytes = file.getBytes();
Path path = Paths.get(UPLOADED_FOLDER + file.getOriginalFilename());
Files.write(path, bytes);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded '" + file.getOriginalFilename() + "'");
processExcel();
} catch (IOException e) {
e.printStackTrace();
}
return "greaat";
}
public String processExcel() throws IOException {
try {
InputStream ExcelFileToRead = new FileInputStream("C:\\\\list.xlsx");
//définir l'objet workbook
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
//Itérer sur le nombre de sheets
for(int i=0;i<wb.getNumberOfSheets();i++)
{
XSSFSheet sheet = wb.getSheetAt(i);
//Itérer sur les lignes
Row row;
for(int k=1;k<sheet.getLastRowNum()+1;k++)
{
row = (Row) sheet.getRow(k); //sheet number
int idPoste;
if( row.getCell(0)==null) { idPoste = 0; }
else idPoste= (int) row.getCell(0).getNumericCellValue();
String libelle;
if( row.getCell(1)==null) { libelle = "null";} //suppose excel cell is empty then its set to 0 the variable
else libelle = row.getCell(1).toString(); //else copies cell data to name variable
System.out.println(libelle);
System.out.println(idPoste);
}
}} catch (Exception e) {
System.err.println("Erreur");
// TODO Auto-generated catch block
e.printStackTrace();
}
return "data extracted successfully";
}
}

Temp png file from storage not uploading

Okay, I don't believe this is a cn1 issue, but I am running out of options. I have an app and I have been using the Capture.capturePhoto to give the user the ability to snap a photo with their device and upload it to my server. Has been working great for several months now. I have been asked to add the ability to upload a photo from the mobiles photo gallery, I thought it would be trivial, but after figuring out how to scale the image down and store it in Storage, I am now stumped with it just sending 0 bytes to my server.
I know it's not my server, that has not changed and can still upload files from various sources including the ones captured with the photo in the cn1 app.
Here is the code that uploads the photo
private void uploadImage(String filename, String name) throws IOException {
String ext = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase();
if (ext.equals("jpg") || ext.equals("jpeg") || ext.equals("pjpeg") || ext.equals("png")) {
MultipartRequest request = new MultipartRequest() {
Hashtable h;
#Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
h = p.parse(new InputStreamReader(input));
super.readResponse(input);
}
#Override
protected void postResponse() {
List<Map<String, Object>> media = (List<Map<String, Object>>)h.get("media");
Dialog.show("Photo Uploaded", media.size() + " photo(s) uploaded and available to send.", "OK", null);
}
};
request.setUrl(MyApplication.IMGSERVER);
request.setPost(true);
request.addData(name, filename, "image/" + ext);
request.addRequestHeader("X-Dart-Token", token);
NetworkManager.getInstance().addToQueue(request);
} else {
Dialog.show("Invalid Photo Format", "The photo format (" + ext+ ") is not supported. Try with jpg or png.", "OK", null);
}
}
Here is the relevant parts of code that get and scale the photo from the gallery
Display.getInstance().openGallery(new ActionListener() {
#Override
public void actionPerformed(ActionEvent actionEvent) {
if (actionEvent != null && actionEvent.getSource() != null) {
String filepath = (String)actionEvent.getSource();
if (filepath != null) {
// scale down the image
String filename = "tempfile.png";
boolean success = false;
if (Storage.isInitialized()) {
try {
OutputStream out = Storage.getInstance().createOutputStream(filename);
ImageIO.getImageIO().save(filepath, out, ImageIO.FORMAT_PNG, 500, -1, 1);
out.close();
success = true;
} catch (IOException e1) {
Log.p("image scaling failed " + e1.getMessage());
Dialog.show("Photo Upload", "Unable to scale photo:" + e1.getMessage(), "OK", null);
}
if (success) {
// open dialog and have user provide name
try {
String tmpFilepath = FileSystemStorage.getInstance().getAppHomePath() + filename;
Dialog.show("Image File", tmpFilepath, "OK", null);
uploadImage(tmpFilepath, name);
} catch (IOException err) {
Log.p("Image Upload Failed:" + err.getMessage());
Dialog.show("Picture Uploaded Failed", "Something prevented the upload of the image.", "OK", null);
}
}
}
}
}
}
I purposely cut out a lot of the surrounding code in the above snippet to focus on what I believe to be important.
I left in the Dialog statements that I am using for debugging so I can see what the path is on the device. If I run this in the simulator, and choose a file, it uploads fine, but when I run it on an iPhone, the file sent to the server has 0 bytes, and the Dialog in the uploadImage method will display that '0 photo(s) uploaded'. When using Storage.g.entrySize() on "tempfile.png" it displays the file has not being 0 in size. How can I properly reference this file to send it to the server.
You are saving the gallery image to Storage but the upload method works with FileSystemStorage those aren't compatible so you get incompatible behaviors.

how to upload multiple files in c# windows application

I want to upload multiple files using single upload button. When I select more than one files it uploads and leaves rest of the files. Here is my code:
private void buttonBrowse_Click(object sender, EventArgs e)
{
try
{
var o = new OpenFileDialog();
o.Multiselect = true;
if (o.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string FileName = o.FileName;
string filenames = Path.GetFileName(o.FileName);
FileName = FileName.Replace(filenames,"").ToString();
FTPUtility obj = new FTPUtility();
if (obj.UploadDocsToFTP(FileName, filenames))
{
MessageBox.Show("File Uploaded Successfully...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
loadfiles();
}
}
else
{
MessageBox.Show("File Not Uploaded", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
this.LoadFiles();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Set MultiSelect property of OpenFileDialog to true and then use FileNames property to get all selected files.
o.FileNames.ToList().ForEach(file =>
{
//upoaad each file separately
});
FileNames
Gets the file names of all selected files in the dialog box.
For example your code may be like this:
var o = new OpenFileDialog();
o.Multiselect = true;
if (o.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var ftp = new FTPUtility();
var failedToUploads= new List<string>();
var uploads= new List<string>();
o.FileNames.ToList().ForEach(file =>
{
var upload= ftp.UploadDocsToFTP(file, Path.GetFileName(file)));
if(upload)
uploads.Add(file);
else
failedToUploads.Add(file);
});
var message= string.Format("Files Uploaded: \n {0}", string.Join("\n", uploads.ToArray()));
if(failedToUploads.Count>0)
message += string.Format("\nFailed to Upload: \n {0}", string.Join("\n", failedToUploads.ToArray()));
MessageBox.Show(message);
this.LoadFiles();
}
This way you can show a message that informs the user about his uploaded files or which one of them that is failed to upload.

display bytes from database as image in imageview in javafx

please I have been stuck on how to convert my stored images from my
database and display it as an image in imageview in javafx.
All the
previously asked questions have not helped me.
I'm using objectdb as my database
I also used fxml to build my GUI
for (Person p : person) {
name.setText(p.getName());
gender.setText(p.getGender());
byte[] byteArray = p.getImage();
image.setImage(new Image(new ByteArrayInputStream(byteArray)));
}
I'll show a detailed step on saving to the database using a file chooser and writing an image to a file in a directory(folder) on your hard drive, and also displaying it to imageview in fmxl GUI.
The following below are triggered during a button event or initialized
from the controller
FileChooser choose = new FileChooser();
FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG");
FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG");
choose.getExtensionFilters().addAll(extFilterJPG, extFilterPNG);
File file = choose.showOpenDialog(null);
try {
BufferedImage bufferedImage = ImageIO.read(file);
byte[] b;
try (ByteArrayOutputStream out = new ByteArrayOutputStream(262144)) {
ImageIO.write(bufferedImage, "jpg", out);
out.flush();
b = out.toByteArray();
}
EntityService service = new EntityService();
Person p = new Person();
p.setId(UUID.randomUUID().toString());
p.setImage(b);
service.putPerson(p);
} catch (IOException e) {
e.printStackTrace();
}
Person p = service.getPerson();
byte[] byteArray = p.getImage();
ByteArrayInputStream in = new ByteArrayInputStream(byteArray);
BufferedImage read = ImageIO.read(in);
image.setImage(SwingFXUtils.toFXImage(read, null));
String output = "C:\\java\\images\\1.jpg";
try (FileOutputStream fos = new FileOutputStream(output)) {
fos.write(byteArray);
} catch (FileNotFoundException ex) {
System.out.println("FileNotFoundException : " + ex);
} catch (IOException ioe) {
System.out.println("IOException : " + ioe);
}

Resources