We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Inserting rtf Text

Hi,


i need to insert a rtf Text to the pdf document i am building.
I have the rtf text in a text file. (Example attached)

Is there any possibility to write this rtf into pdf document, using its style format?

Greetings,

Crazkur

Hi Crazkur,


Thanks for your inquiry. I am afraid Aspose.Pdf does not support to insert RTF text in PDF document at the moment, so we have logged a new feature request PDFNET-42241 for same. We will notify you as soon as it is implemented.

However as a workaround, you can accomplish your task with collaboration of Aspose.Words and Aspose.Pdf. In first step convert your RTF text to HTML using Aspose.Words as following and then add HTML text in PDF document using Aspose.Pdf.

string filePath = myDir + “test.rtf”;<o:p></o:p>

Aspose.Words.FileFormatInfo info = Aspose.Words.FileFormatUtil.DetectFileFormat(filePath);

Console.WriteLine(info.LoadFormat);

Aspose.Words.LoadOptions loadOptions = new Aspose.Words.LoadOptions();

loadOptions.LoadFormat = Aspose.Words.LoadFormat.Rtf;

Aspose.Words.Document doc = new Aspose.Words.Document(filePath, loadOptions);

doc.Save(myDir + @"17.2.0.html");


Best Regards,

Hi,


thanks for your answer. Atm I am using a converter to convert my rtf to html. Therefore i dont need Aspose.Words.

Converter conv = new Converter();

byte[] content = Encoding.Default.GetBytes(rtfField.RtfText);

String htmlText = conv.ConvertRtfToHtml(content);

HtmlFragment html = new HtmlFragment(htmlText);

aspose_page.Paragraphs.Add(html);

This is what i am doing now. The Text i want to add is in my PdfDocument, but somehow always on a new page. I debugged it and from start to end my created Document contains only one page (i.e. aspose_page).

I need to be able to place the text wherever I want on the page i am building.
Is there any possible way to do this?

Greetings,

Crazkur

Hi Crazkur,


Thanks for your feedback. If you want to add Html text on some specific postion then you may use FloatingBox as following, hopefully it will help you to accomplish the task. However if the issue persist then please share your sample html text along with sample code, so we will test the scenario at our end and will guide you accordingly.

Aspose.Pdf.Document
doc = new Aspose.Pdf.Document();<o:p></o:p>

var page = doc.Pages.Add();

//page.PageInfo.Margin.Left = 0;

//page.PageInfo.Margin.Top = 0;

var floatingBox = new Aspose.Pdf.FloatingBox(200, 250)

{

Left = 0,

Top = 100

};

floatingBox.Paragraphs.Add(new Aspose.Pdf.HtmlFragment(html));

page.Paragraphs.Add(floatingBox);

doc.Save("FloatingBox.pdf");


Best Regards,

Hi,


i use the FloatingBox now and it works fine :slight_smile:
I am not able to modify my htmlFragment for example in FontSize, am I?

Anyway, thanks for your help.

Greetings,

Crazkur

Hi Crazkur,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirement.

Furthermore in reference to setting FontSize of HtmlFragment, currently HtmlFragment does not support font setting. We have already logged an enhancement ticket PDFNET-41905 in our issue tracking system for same. We have linked your post to the issue id and will notify you as soon as it is resolved. However as a workaround, you may use CSS within your HTML text for font settings.

Best Regards,

Hi Crazkur,


Adding more to Tilal’s comments, in order to set font formatting for HtmlFragment, you may consider defining it inside the Html text i.e. <span style=“color: rgb(51, 34, 170); font-family: Verdana, “Courier New”, Courier, monospace; font-size: 10.8px; background-color: rgb(252, 252, 255);”><font <strong style=“color: rgb(51, 34, 170); font-family: Verdana, “Courier New”, Courier, monospace; font-size: 10.8px; background-color: rgb(252, 252, 255);”>face<span style=“color: rgb(51, 34, 170); font-family: Verdana, “Courier New”, Courier, monospace; font-size: 10.8px; background-color: rgb(252, 252, 255);”>=“Arial”>Your text here.

Hi,


i am pretty sure this is a mistake in my converter, but I´ll consider defining font in html. Just in case.

Many Thanks for your help guys :slight_smile:

Greetings,

Crazkur

Hi Crazkur,


Thanks for the acknowledgement.

Please continue using our API and in the event of any further query, please feel free to contact. Furthermore, as soon as we have some definite updates regarding the resolution/implementation of earlier reported issues, we will update you within this forum thread.

Your patience and comprehension is greatly appreciated in this regard.

The issues you have found earlier (filed as PDFNET-41905) have been fixed in Aspose.Pdf for .NET 17.3.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Crazkur,


Thanks for your patience. In reference to above fix, we have introduced TextState method in HtmlFragment class in Aspose.Pdf for .NET 17.3.0. Now, you can set font settings of HTML string as following.

Aspose.Pdf.Document
doc = new Aspose.Pdf.Document();<o:p></o:p>

Page page = doc.Pages.Add();

HtmlFragment html = new HtmlFragment("some text");

html.TextState = new TextState();

html.TextState.Font = FontRepository.FindFont("Calibri");

page.Paragraphs.Add(html);

doc.Save(myDir+"test.pdf");


Best Regards,