i created a mule flow which accepts a file as inputstream and convert into byte array and attach that file to the particular SalesForce case.
Can it possible that i could convert the file(coming as inputstream) to the pdf format and attach to Salesforce case.
PDF is a special format so directly it will not create PDF. You can use libraries like Apache FOP or iText to create PDF output.
Related
I'm trying to get a .png file to render in a WebView after getting the file through an apache HttpClient get request. I'm actually reading the HttpResponse contents into a simple byte array -> (evaluating the contents into a String when debugging).
It appears if I convert those bytes into a string to compare with the actual file, they look different. Is there a specific way to retrieve .png file
using the apache HttpClient?
example compare, my test is on the left and actual file on right
I am getting a base64 PDF input as part of a request from my client, I need to convert this file into to File Input Stream to use with the PDF BOX library. I am trying to achieve this without writing the file onto drive and directly reading the base64 pdf into File Input Stream.
What I am able to do:
Convert base64 encoded pdf to File and write on the drive
Read the file into a File Input Stream
What I want to do:
Convert base64 encoded PDF to File input stream to use it with PDFBOX.
I am trying to avoid writing the file onto the disk.
In pdfbox you can load a pdf from an InputStream. it does not need to be FileInputStream.
Using the following code you can get an inputStream of the decoded pdf.
Note: depending on the scheme used to encode pdf you may need to use: .getMimeDecoder() instead of .getDecoder().
InputStream decoded = java.util.Base64.getDecoder().wrap(inputStream);
PDDocument.load(decoded);
I have to upload a file attachment and send it via an HTTP GET request to a server location. I am using IBM websphere integration designer to implement this functionality.
I have the attachment as a byte array and it has to be converted to an Excel .csv file.
Please help me understand how to write a .csv file using a byte array.
If you have a byte array. Let's say.
byte[] byteArray = ThisIsWhereMyByteArrayIsComingFrom.getArray();
String convertedString = new String(byteArray);
That gets the string value of whatever your byte array is. Then you can either, use a csv library to output whatever it is to a file.
I have a solution that inserts strings into an XHTML document and prints the results as Reports. My employer has asked if we could pull images off their SQL database (stored as byte arrays) to insert into the Reports.
I am using FlyingSaucer as the XHTML interpreter and I've been using Java DOM to modify pre-stored reports that I have stored in the Report Generator's package.
The only solution I can think of at the moment is to construct the images, save them as a file, link the file in an img tag (or background-image) in a constructed report, print the report and then delete the file. This seems really sloppy and I imagine it will be very time consuming.
I can't help but feel there must be a more elegant solution. Any suggestions for inserting a byte array into html?
Read the image and convert it into it's Base64-encoded form:
InputStream image = getClass().getClassLoader().getResourceAsStream("image.png");
String encodedImage = BaseEncoding.base64().encode(ByteStreams.toByteArray(image));
I've used BaseEncoding and ByteStreams from Google Guava.
Change src attribute of img element within your Document object.
Document doc = ...; // get Document from XHTMLPanel.getDocument() or create
// new one using DocumentBuilderFactory
doc.getElementById("myImage").getAttributes().getNamedItem("src").setNodeValue("data:image/png;base64," + encodedImage);
Unfortunatley FlyingSaucer does not support DataURIs out-of-the-box so you'll have to create your own ReplacedElementFactory. Read Using Data URLs for embedding images in Flying Saucer generated PDFs article - it contains a complete solution.
I could implement converting the old .doc files to html only with Apache POI.
For .docx, however, I had to use the fr.opensagres.xdocreport package.
Code is pretty straightforward:
XWPFDocument document = new XWPFDocument(inputStream);
OutputStream outputStream = new ByteArrayOutputStream();
XHTMLOptions options = XHTMLOptions.create().indent(4).setImageManager(new Base64EmbedImgManager());
XHTMLConverter.getInstance().convert(document, outputStream, options);
return outputStream.toString();
However, there two issues:
embedded excel charts are ignored (the .doc conversion with Apache POI converts them to images just like it does with any other normal image)
text that has custom various format combinations is not rendered correctly, several new-lines are inserted unnecessarily. ( see input and output examples)
Does anybody know any way to fix this ?
Thank you.