Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Create a File RTF or PDF whit text formatted and images
Create a File RTF or PDF whit text formatted and images [message #504482] Sun, 20 December 2009 11:10 Go to next message
Antonio is currently offline AntonioFriend
Messages: 39
Registered: July 2009
Member
Hi to all,

i have this problem, i write a RCP and i use SWT library.

In this RCP i create a little WordProcessor, i use styleText library.

I can manipolate text and insert a image.

Now i want to create a file (RTF or PDF), this file have the text formatted
and the images

but i don't have idea that to do.

I see the open source progect itext(http://itextpdf.com/) but i don't know
that i use this libraries whit styledText, can you help me?

best regads

Antonio
Re: Create a File RTF or PDF whit text formatted and images [message #504569 is a reply to message #504482] Mon, 21 December 2009 09:56 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Antonio,

StyledText has inner class RTFWriter, which writes a StyledText's content in
RTF format. Unfortunately this class is not public, so your choices are:

1. Use it indirectly by invoking StyledText.copy(). This writes an RTF
version of your content to the clipboard, which you can get at and save to a
file (example snippet below). The drawback with this approach is that the
user's previous clipboard content gets overwritten.

public static void main(String[] args) {
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final StyledText text = new StyledText(shell, SWT.NONE);
text.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
text.copy();
Clipboard cb = new Clipboard(display);
RTFTransfer transfer = RTFTransfer.getInstance();
String data = (String)cb.getContents(transfer);
System.out.println(data);
cb.dispose();
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

2. Make a public copy of the RTFWriter class.

3. Using introspection you may be able to create an instance of StyledText's
RTFWriter, even though it's not a public class. If this succeeds then you
should be able to use it in place.

I have no idea about creating a PDF, you'll have to look around at third
party libraries. Maybe there's something out there that can create a PDF
from an RTF?

HTH,
Grant


"Antonio De Curtis" <adecurtis99@yahoo.it> wrote in message
news:hgl0mv$rsu$1@build.eclipse.org...
> Hi to all,
>
> i have this problem, i write a RCP and i use SWT library.
>
> In this RCP i create a little WordProcessor, i use styleText library.
>
> I can manipolate text and insert a image.
>
> Now i want to create a file (RTF or PDF), this file have the text
formatted
> and the images
>
> but i don't have idea that to do.
>
> I see the open source progect itext(http://itextpdf.com/) but i don't know
> that i use this libraries whit styledText, can you help me?
>
> best regads
>
> Antonio
>
Re: Create a File RTF or PDF whit text formatted and images [message #504973 is a reply to message #504569] Wed, 23 December 2009 21:33 Go to previous message
Antonio is currently offline AntonioFriend
Messages: 39
Registered: July 2009
Member
Hi Grant thanks for your answer,
i see itextpdf for create a pdf file(this package create pdf, rtf and html
file)
now i'm studing to use this package whit styledtext.

regads
Antonio



"Grant Gayed" <grant_gayed@ca.ibm.com> ha scritto nel messaggio
news:hgo25d$99e$1@build.eclipse.org...
> Hi Antonio,
>
> StyledText has inner class RTFWriter, which writes a StyledText's content
> in
> RTF format. Unfortunately this class is not public, so your choices are:
>
> 1. Use it indirectly by invoking StyledText.copy(). This writes an RTF
> version of your content to the clipboard, which you can get at and save to
> a
> file (example snippet below). The drawback with this approach is that the
> user's previous clipboard content gets overwritten.
>
> public static void main(String[] args) {
> final Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> final StyledText text = new StyledText(shell, SWT.NONE);
> text.addListener(SWT.MouseDoubleClick, new Listener() {
> public void handleEvent(Event event) {
> text.copy();
> Clipboard cb = new Clipboard(display);
> RTFTransfer transfer = RTFTransfer.getInstance();
> String data = (String)cb.getContents(transfer);
> System.out.println(data);
> cb.dispose();
> }
> });
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch()) display.sleep();
> }
> display.dispose();
> }
>
> 2. Make a public copy of the RTFWriter class.
>
> 3. Using introspection you may be able to create an instance of
> StyledText's
> RTFWriter, even though it's not a public class. If this succeeds then you
> should be able to use it in place.
>
> I have no idea about creating a PDF, you'll have to look around at third
> party libraries. Maybe there's something out there that can create a PDF
> from an RTF?
>
> HTH,
> Grant
>
>
> "Antonio De Curtis" <adecurtis99@yahoo.it> wrote in message
> news:hgl0mv$rsu$1@build.eclipse.org...
>> Hi to all,
>>
>> i have this problem, i write a RCP and i use SWT library.
>>
>> In this RCP i create a little WordProcessor, i use styleText library.
>>
>> I can manipolate text and insert a image.
>>
>> Now i want to create a file (RTF or PDF), this file have the text
> formatted
>> and the images
>>
>> but i don't have idea that to do.
>>
>> I see the open source progect itext(http://itextpdf.com/) but i don't
>> know
>> that i use this libraries whit styledText, can you help me?
>>
>> best regads
>>
>> Antonio
>>
>
>
Previous Topic:best way of accessing the size of text between tabs on each line?
Next Topic:Writing Help/Doc for standalone SWT application
Goto Forum:
  


Current Time: Tue Mar 19 08:33:15 GMT 2024

Powered by FUDForum. Page generated in 0.02842 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top