I am using itext 2.1.7 to create a rtf file dynamically in a spring MVC controller.
The class I am using is RTFWriter2. This works well. But I am not able to add an image to it.
The image is a byte array which I get from a JPA domain object. I also tried to read a sample image from a file. But this does not work either. The image class is from the itext package and its constructor allows an byte array.
This is the code I use:
Image img = Image.getInstance(user.getStammdaten().getProfileImage());
document.add(img);
document.newPage();
Any clues?
Maybe this scripst will help you.
https://joseluisbz.wordpress.com/2011/06/22/script-de-clases-rtf-para-jsp-y-php/
Now,
Here there is an example of use:
https://joseluisbz.wordpress.com/2011/07/16/subiendo-imagenes-png-y-jpg-y-archivos-a-mysql-con-php-y-jsp-y-mostrarlos-en-rtf-usando-clases/
Related
I have requirement to export pdf from local database, And I have done this for image and text it work perfect, but I want to print emoji on a PDF and I don't know how. If anyone has an idea, please reply. For PDF export I am using iTextPDF and for Emoji Emojicon.
Maybe you can use https://github.com/pepibumur/emojize for add emojis to your project. There are methods for parsing or sth:
public static String emojiText(String text){}
public static String demojizedText(String text){}
There are emoji graphics and apis https://github.com/arvida/emoji-cheat-sheet.com
I am trying to create a java project that simply prints a project source code, be it java, php, c++ and others.
I can create the PDF just fine with iText, but now I need some kind of highlighting the java code I read the same way a code editor like sublime highlights. I discovered pdfbox: a library for creating/manipulating PDF files, but I can't find how to highlight code text(like sublime does) by using this library. Any help?
Copying from another SO question : highlight text using pdfbox when it's location in the pdf is known
PDDocument doc = PDDocument.load(/*path to the file*/);
PDPage page = (PDPage)doc.getDocumentCatalog.getAllPages.get(i);
List annots = page.getAnnotations;
PDAnnotationTextMarkup markup = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.Su....);
markup.setRectangle(/*your PDRectangle*/);
markup.setQuads(/*float array of size eight with all the vertices of the PDRectangle in anticlockwise order*/);
annots.add(markup);
doc.save(/*path to the output file*/);
I am using the Apache PDF box library to convert a PDF page to PNG image format.
I have used both the ImageWriter and PDFImageWriter to write the "BufferedImage" object to a file in png format.
The BufferedImage object is created from the "convertToImage" method available from the pdf document object.
When the image is created and the image writer and document objects are closed, the execution does not stop and it looks like soem stream or background thread is still running.
I tried all this using a single main function in Java so that I know that the only operation running is the conversion code from pdf page to an image file.
I tried setting the image writer and document objects to null after closing/disposing the objects but I have had no success in this regard.
What I am missing? Please advise with some sample code.
Thanks in advance.
Subbu
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 hava a Java/Grails app that needs to "read" the contents of a given URL to use it as an image, mostly to be dinamically resized.
My app already parses the url into HTML code using an implementation based on this post: http://www.roseindia.net/java/example/java/io/SourceViewer.shtml.
The class I built returns a String object that contains the HTML source code. Now I want to write this String into an object similar to a BufferedImage so I can display the captured URL into my new application.
any ideas, thanks in advance!
You can use a service like Bluga.net WebThumb and use Glen Smith's ThumbnailService to interface with it.
Or, if you really want to do this by yourself, you can use his Thumbnail Server (with an older version of the ThumbnailService), that he used to use before migrating to WebThumb ;)
Regards
You can create an Image object from a url :
URL url = new URL("http://url.to/your/image.jpg";
Image image = Toolkit.getDefaultToolkit().createImage(url)
If by
take a 'print screen' of the this site
you mean display in your app take a look at this : http://www.java-tips.org/java-se-tips/javax.swing/how-to-display-pages-for-a-web-site-in-your-applic.html