|
I downloaded
Download executable files (DLL + demo + docs) - 548.9 KB
pasted the dll in the Program Files directory, added reference still on the statement
using Net.Sgoliver.NRtfTree.Util;
I get error The type or namespace name 'Net' could not be found (are you missing a using directive or an assembly reference?)
what could be wrong?
|
|
|
|
|
Why wmetafile image dimensions, when are extracted with application, appears differents from what selected via \picwgoal and \pichgoal tags?
Seems application it is "insensible" to parameter picgoal.
When application extracts wmetafile image content in "example1-images.rtf" of examples (they ar hidden, in file), it create WMF file with dimension not correct (cfr. jpg image from same file...).
Help me!!!
|
|
|
|
|
Hi Oliver,
i've added a new class capable to make multiple RTF doc merge.
I am very plase to add my class to your project.
Plase contact me i will send you source file.
Regards
Sample Code:
private void cmdMerge_Click(object sender, EventArgs e)
{
// create main Rtf doc and insert into main doc rtf placeholder
RtfDocument doc = new RtfDocument("..\\..\\SampleDoc\\RtfDoc.rtf");
RtfTextFormat textFmt = new RtfTextFormat();
textFmt.font = "Times New Roman";
textFmt.bold = true;
doc.AddText("[TagTextRTF1] Test File with placeholder [TagTextRTF1], place holder will be replaced with RTF file. Second Place holder into same line [TagTextRTF2].", textFmt);
textFmt.bold = false;
textFmt.underline = true;
textFmt.color = Color.Red;
doc.AddText("Second text (RED underlined text) with following place holder [TagTextRTF2]", textFmt);
doc.Close();
// create first to merge rtf doc
doc = new RtfDocument("..\\..\\SampleDoc\\ToMerge1.rtf");
textFmt = new RtfTextFormat();
textFmt.font = "Georgia";
textFmt.color = Color.Blue;
textFmt.bold = false;
doc.AddText("(Hi, i'm RTF content of your 1st placeholder)", textFmt);
doc.Close();
// create second to merge rtf doc
doc = new RtfDocument("..\\..\\SampleDoc\\ToMerge2.rtf");
textFmt = new RtfTextFormat();
textFmt.font = "Verdana";
textFmt.color = Color.Green;
textFmt.bold = false;
doc.AddText("(Hi, i'm RTF content of your 2nd placeholder)", textFmt);
doc.Close();
RtfMerger oTree = new RtfMerger();
oTree.MergeRtfDoc("..\\..\\SampleDoc\\RtfDoc.rtf", "\\[TagTextRTF(\\w+)\\]", new OtherRtfDocDelegate(manageDocToInsert), "..\\..\\SampleDoc\\Result.rtf", false,true);
MessageBox.Show("Test ended!");
}
public void manageDocToInsert(ref RtfTree docToInsert, string strText , string strPHParam, ref string strCompletePlaceHolder)
{
if (strPHParam == "1")
{
docToInsert = new RtfTree();
docToInsert.LoadRtfFile("..\\..\\SampleDoc\\ToMerge1.rtf");
}
if (strPHParam == "2")
{
docToInsert = new RtfTree();
docToInsert.LoadRtfFile("..\\..\\SampleDoc\\ToMerge2.rtf");
}
}
BoFabio
|
|
|
|
|
Hi, I need your class. Please, can you send me it at the email address vifani[at]gmail[dot]com ?
|
|
|
|
|
Hi Fabio,
Actually, i'm now working on the merging rtf files. I'm wondering if your classes can merge any 2 rtf files(the 2 rtf files' format may have many differences)?
Would you please share your source codes?(My email:kevin[dot]yank[at]gmail[dot]com)
Many thanks
Kevin
|
|
|
|
|
I need the code to merge multiple RTF file.
|
|
|
|
|
Hi Olivel,
compliment for your good job.
I've discovered a couple of small bugs in your job.
How can i send to you this bug fixing?
Reading complex rtf i've discovered fonttbl big issues.
Fonttbl font are not enumerated from 0 to last font in progressive order, sometimes we have a non continuous range.
For example we could have four different font in fonttbl managed as follow: font 0, font 1, font 4 and font 5.
I've modified RtfFontTable and RtfTree source.
Contact me as soon
Thank you
Fabio
BoFabio
modified on Friday, October 24, 2008 6:09 AM
|
|
|
|
|
Hi,
could you provide here what you corrected?
Thanks.
|
|
|
|
|
There's a bug - characters '{', '}' and '\\' aren't prefixed with '\\' in AppendEncoded method
To fix it add this code into AppendEncoded in the loop right before "int code = Char.ConvertToUtf32(s, i);":
if ((s[i] == '{') || (s[i] == '}') || (s[i] == '\\'))
{
res.Append(@"\");
}
|
|
|
|
|
I have translated code of TraductorRtf (for RTF2HTML conversion) in Delphi-pascal and it works very well. Images must be saved before and RTF code must be replaced with reference at their location....
Here is code.
Buona fortuna.
{*
************************************************************************** * This file is part of NRtfTree.
*
* NRtfTree is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* NRtfTree is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NRtfTree; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**************************************************************************************************************************************************** * Library: NRtfTree
* Version: v0.2.1
* Class: ImageNode
* Copyright: 2005 Salvador Gomez
* Home Page: http:
* SF Project: http:
* http:
* Date: 10/12/2006
* Description: Conversor simple de RTF a HTML (Demo NRtfTree)
* Translated from C# to Delphi: 2008 Nicolò Blunda
***************************************************************************}
UNIT TraductorRtf;
INTERFACE
USES System.Collections, System.Drawing, System.Drawing.Drawing2D, Borland.Vcl.SysUtils,
Net.Sgoliver.NRtfTree.Core, Net.Sgoliver.NRtfTree.Util;
TYPE
EstadoRtf = class
public
negrita: Boolean;
cursiva: Boolean;
subrayado: Boolean;
fuente: string;
tamFuente: Integer;
color: Color;
public
constructor Create(fue: string; tam: Integer; col: Color; neg: Boolean; cur: Boolean;
sub: Boolean);
end;
TArrayOfString = array of string;
TArrayOfColor = array of Color;
TraductorRtf = class
strict private
tree: RtfTree;
tFuentes: TArrayOfString;
tColores: TArrayOfColor;
estados: ArrayList;
estadoActual: EstadoRtf;
public
constructor Create(TextRTF: string);
function traducir: string;
function traducTexto: string;
function traducirTexto(curNode: RtfTreeNode; prim: Integer): string;
function inicioFormato: string;
function finFormato: string;
function toHTMLColor(actColor: Color): string;
function intToHex(hexint: Integer; lungh: Integer): string;
end;
IMPLEMENTATION
constructor EstadoRtf.Create(fue: string; tam: Integer; col: Color; neg: Boolean;
cur: Boolean; sub: Boolean);
begin
inherited Create;
Self.fuente := fue;
Self.tamFuente := tam;
Self.color := col;
Self.negrita := neg;
Self.cursiva := cur;
Self.subrayado := sub;
end;
constructor TraductorRtf.Create(TextRTF: string);
begin
inherited Create;
Self.estados := ArrayList.Create;
Self.tree := RtfTree.Create;
Self.tree.LoadRtfText(TextRTF);
end;
function TraductorRtf.traducir: string;
Begin
Result:= '';
Self.tFuentes := Self.tree.GetFontTable;
Self.tColores := Self.tree.GetColorTable;
Result:= traducTexto;
End;
function TraductorRtf.traducTexto: string;
var
primerNodoTexto: Integer;
nodo: RtfTreeNode;
i: Integer;
enc: Boolean;
res: string;
Begin
res:= '<html><head></head><body>';
Self.estadoActual:=
EstadoRtf.Create((string(Self.tFuentes[0])), 10, (Color(Self.tColores[0])),
False, False, False);
inicioFormato;
enc := False;
i := 0;
nodo := RtfTreeNode.Create;
while ((not enc ) and (i < Self.tree.RootNode.FirstChild.ChildNodes.Count)) do
begin
nodo := Self.tree.RootNode.FirstChild.ChildNodes[i];
enc := (nodo.NodeKey = 'pard');
Inc(i);
end;
primerNodoTexto := (i - 1);
res:= res + traducirTexto(tree.RootNode.FirstChild, primerNodoTexto);
res:= res + finFormato;
res:= res + '</body></html>';
Result:= res;
End; {traducTexto}
function TraductorRtf.traducirTexto(curNode: RtfTreeNode; prim: Integer): string;
var
i: Integer;
nodo: RtfTreeNode;
nprin: RtfTreeNode;
res: string;
Begin
res := '';
nprin := curNode;
nodo := RtfTreeNode.Create;
for i:= prim to nprin.ChildNodes.Count - 1 do
begin
nodo := nprin.ChildNodes[i];
if (nodo.NodeType = RtfNodeType.Group) then
begin
Self.estados.Add(Self.estadoActual);
Self.estadoActual := EstadoRtf.Create((string(Self.tFuentes[0])), 10, (Color(Self.tColores[0])),
False, False, False);
res:= res + traducirTexto(nodo,0);
Self.estadoActual := (EstadoRtf(Self.estados[(Self.estados.Count - 1)]));
Self.estados.RemoveAt((Self.estados.Count - 1));
end
else if (nodo.NodeType = RtfNodeType.Control) then
begin
if (nodo.NodeKey = '''') then
begin
res:= res + inicioFormato;
res:= res + Char(nodo.Parameter);
res:= res + finFormato;
end
end
else if (nodo.NodeType = RtfNodeType.Keyword) then
begin
if nodo.NodeKey='f' then
estadoActual.fuente:= tFuentes[nodo.Parameter]
else if nodo.NodeKey='cf' then
estadoActual.color:= tColores[nodo.Parameter]
else if nodo.NodeKey='fs' then
estadoActual.tamFuente:= nodo.Parameter
else if nodo.NodeKey='b' then
estadoActual.negrita:= (not nodo.HasParameter or (nodo.Parameter=1))
else if nodo.NodeKey='i' then
estadoActual.cursiva:= (not nodo.HasParameter or (nodo.Parameter=1))
else if nodo.NodeKey='ul' then
estadoActual.subrayado:= true
else if nodo.NodeKey='ulnone' then
estadoActual.subrayado:= false
else if nodo.NodeKey='par' then
res:= res + '<br>';
end
else if (nodo.NodeType = RtfNodeType.Text) then
begin
res := res + inicioFormato;
res := res + nodo.NodeKey;
res := res + finFormato;
end;
end; {for i}
Result := res;
End; {traducirTexto}
function TraductorRtf.inicioFormato: string;
var
res: string;
begin
res:= '';
res:= '<font face=''' + estadoActual.fuente + ''' size=''' + FloatToStr(Int(estadoActual.tamFuente/8)) + ''' color=''' + toHTMLColor(estadoActual.color) + '''>';
if Self.estadoActual.negrita then
res:= res + '<b>';
if Self.estadoActual.cursiva then
res:= res + '<i>';
if Self.estadoActual.subrayado then
res:= res + '<u>';
Result := res;
end;
function TraductorRtf.finFormato: string;
var
res: string;
begin
res := '';
if Self.estadoActual.negrita then
res:= res + '</b>';
if Self.estadoActual.cursiva then
res:= res + '</i>';
if Self.estadoActual.subrayado then
res:= res + '</u>';
Result := res;
end;
function TraductorRtf.toHTMLColor(actColor: Color): string;
Begin
Result := ((('#' + intToHex(actColor.R, 2)) + intToHex(actColor.G, 2)) + intToHex(actColor.B, 2));
End;
function TraductorRtf.intToHex(hexint: Integer; lungh: Integer): string;
var
i: Integer;
relleno: Integer;
hexstr: string;
Begin
hexstr := Convert.ToString(hexint, 16);
relleno := (lungh - hexstr.Length);
for i:= 0 to relleno do hexstr := ('0' + hexstr);
Result := hexstr;
End;
END.
|
|
|
|
|
If "LoadRtfText()" is called with a plaintext string instead of RTF, accessing the ".text" property causes an "System.ArgumentOutOfRangeException: Index was out of range." exception.
The problem appears to be in "ConvertToTextAux()" in RtfTree.cs. In the case of plaintext, no child nodes are created, and "prim" is passed in as "-1". Because "-1 < 0", the for loop executes when it shouldn't and the "ChildNodes" array is mis-indexed.
My solution to this was to check that "prim >= 0" before entering the for loop. If "prim < 0", then I skip the for loop and just do the following:
res.AppendLine(nprin.NodeKey);
Which just returns the text of the single plaintext node.
Hope that helps anyone else with the same problem.
modified on Wednesday, August 6, 2008 4:20 PM
|
|
|
|
|
Hi, is it possible to merge rtf documents to one document with this library without losing styles, tables etc. from the original documents. An example would be nice. Thank you in advance.
Olli
|
|
|
|
|
Hi,
i've just finished to do this job.
I've done new class to merge different RTF document.
Here is just a small example.
I've asked to project owner to include this my new class.
Regards
// create main Rtf doc and insert into main doc rtf placeholder
RtfDocument doc = new RtfDocument("..\\..\\SampleDoc\\RtfDoc.rtf");
RtfTextFormat textFmt = new RtfTextFormat();
textFmt.font = "Times New Roman";
textFmt.bold = true;
doc.AddText("[TagTextRTF1] Test File with placeholder [TagTextRTF1], place holder will be replaced with RTF file. Second Place holder into same line [TagTextRTF2].", textFmt);
textFmt.bold = false;
textFmt.underline = true;
textFmt.color = Color.Red;
doc.AddText("Second text (RED underlined text) with following place holder [TagTextRTF2]", textFmt);
doc.Close();
// create first to merge rtf doc
doc = new RtfDocument("..\\..\\SampleDoc\\ToMerge1.rtf");
textFmt = new RtfTextFormat();
textFmt.font = "Georgia";
textFmt.color = Color.Blue;
textFmt.bold = false;
doc.AddText("(Hi, i'm RTF content of your 1st placeholder)", textFmt);
doc.Close();
// create second to merge rtf doc
doc = new RtfDocument("..\\..\\SampleDoc\\ToMerge2.rtf");
textFmt = new RtfTextFormat();
textFmt.font = "Verdana";
textFmt.color = Color.Green;
textFmt.bold = false;
doc.AddText("(Hi, i'm RTF content of your 2nd placeholder)", textFmt);
doc.Close();
RtfMerger oTree = new RtfMerger();
oTree.MergeRtfDoc("..\\..\\SampleDoc\\RtfDoc.rtf", "\\[TagTextRTF(\\w+)\\]", new OtherRtfDocDelegate(manageDocToInsert), "..\\..\\SampleDoc\\Result.rtf", true, true);
MessageBox.Show("Test ended!");
}
BoFabio
|
|
|
|
|
|
|
Found issue with other character sets (eg. Chinese/Japanese etc).
Sample rtf string.
"{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\froman\fprq1\fcharset128 Arial Unicode MS;}{\f1\fswiss\fcharset0 Arial;}}{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\sb100\sa100\lang1033\f0\fs24\'82\'d0\'82\'e7\'82\'aa\'82\'c8\lang2057\f1\fs20\par}";
where '82\'d0\'82\'e7\'82\'aa\'82\'c8 is the text. But this is identified as Nodetype = control.
Thanks
Sathish
|
|
|
|
|
How would you parse the RTF document for merge codes and replace them with text?
|
|
|
|
|
Hi,
I would like find and replace text in rtf document, but I don't known how. Could you help me?
RtfTree tree = new RtfTree();
tree.LoadRtfFile(sourceFileName);
//
//Here, I need find and replace string (for example Find: |<CustomerName>| a Replace: Intel)
//
tree.SaveRtf(destinationFileName);
Lada
|
|
|
|
|
Have you solved your task? I've got the same problem!
|
|
|
|
|
I'll try to update the library in two/three weeks.
In the new version you can define templates, merge documents, find/replace text...
|
|
|
|
|
Thanks you so much for this feature, eagarly waiting for this
|
|
|
|
|
Different subject here. Could you provide an example in English on how to merger files?
Thanks
Gary
|
|
|
|
|
Hi, I have been looking at the help file and for the life of me I can't see how to convert rtf to html. Can someone give me a vb code example. Thanks
PQSIK
|
|
|
|
|
NRtfTree is NOT a library to convert RTF to HTML. NRtfTree can help you to proccess RTF documents in a general way, so you won't find any reference to HTML conversion in help files.
However, I have included an example of use of NRtfTree in the zip (Rtf to HTML conversion), but it's ONLY an example, and it's a very basic application. Have a look at the code of TraductorRtf.cs
-- modified at 15:17 Monday 26th November, 2007
|
|
|
|
|
HI.
Good work thanks for it.
I have one note:
In RtfLex class, function parse Text uses this contruction
StringBuilder Texto = new StringBuilder(((char)c).ToString(),3000000);
in my case it throws "Out of memory exception".
I changed it to
StringBuilder Texto = new StringBuilder(((char)c).ToString());
all works fine and speed of parsing increased in 6 times
sorry for bad English
|
|
|
|
|