I want to be able to add a "tick" to the end of a sentence using the DocX library.
//Create the table
Table signingTable = document.AddTable(18, 6);
//....many lines of code
string mySentence = "Hello World" + <tick>;
signingTable.Rows[entryItem + 1].Cells[3].Paragraphs.First().Append(mySentence);
such that when my table renders it will have a tick symbol next to the text Hello World. Can someone help with the encoding I need to add to make this work?
The tick mark is ascii character 252 in the wingdings font.
You need to add another run to the paragraph, set the run font to wingdings and add chr(252) into it.
Using the DocX library you would do something like the following:
char tick = (char) 252;
p.Append("Hello World").Append(tick).Font(new FontFamily("Wingdings"));
Using SDK OpenXML you would do something like this:
p.Append(new Run( new SymbolChar() { Font = "Wingdings", Char = "F0FE" }));
Related
I used Itext7 in my C# code to create a pdf file, as I said in my other question here
Itext7 not showing arabic text
so I gave up on trying to fix it, because it seems like I need to pay for the addon, and I can't do that
I tried Pdf sharp, it showed arabic letters but there were disconnected and reversed, and writing arabic backward did not make the letters connect
I used SautinSoft library and it created a word document where arabic works fine, but it has a footer that says that it is a free version, so i can't use this one either
the pdf created by this library also doesnt support arabic
so I think I can't write pdf in arabic, all libraries I tried didn't supported it
is there anyway to fix it?
or can anyone please suggest another library that can create arabic pdf or a word document without watermarks or footers
I found the solution, using Gembox pdf, it only allows 20 paragraphs, but that is more than enough
What if DocumentCore?
public static void SecureDocument()
{
string filePath = #"ProtectedDocument.pdf";
DocumentCore dc = new DocumentCore();
// Let's create a simple document.
dc.Content.End.Insert("Hello World!!!", new CharacterFormat() { FontName = "Verdana", Size = 65.5f, FontColor = Color.Orange });
PdfSaveOptions so = new PdfSaveOptions();
// Password Protection
so.EncryptionDetails.UserPassword = "12345";
// EncryptionAlgorithm
so.EncryptionDetails.EncryptionAlgorithm = PdfEncryptionAlgorithm.RC4_128;
//Permissions: Content Copying, Commenting, Printing, Changing the Document, filing of form fildes
//Printing: Allowed
so.EncryptionDetails.Permissions = PdfPermissions.Printing;
// Save a document as the PDF file with Security Options.
dc.Save(filePath, so);
// Open the result for demonstration purposes.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
}
I have this string read from a table in sql:
Yderligere tillidshverv:
Medlem af bestyrelsen for Dansk XXSW, region Århus.
Andre aktiviteter:
Opfinder af 123 trapper.
What I want to do is replace occurences of \r\n with just a single \n. However it is not working. The problem is that notepad++ still shows CRLF. It should only show LF. What am I missing? Here is my code:
string x = returnValue.Replace("\r\n", "\n");
When you paste a string from a Windows clipboard into Notepad++, the linebreaks get converted to the line ending style set for the current document (see the bottom of the screen).
If you right click and select UNIX, you will be able to paste the string with \n only. This will also change all line endings to LF.
If you do not want to change all line endings in the document to LF, you can use EDIT > Paste Special -> Paste Binary Content
However, from C#, you can just write the variable content into a text file:
var s = "I know\r\nit should\r\n";
var b = s.Replace("\r\n", "\n");
using (var sw = new StreamWriter(#"PATH_TO_FILE", false, Encoding.UTF8))
{
sw.Write(b);
}
And enjoy \n linebreaks.
Using the Regex class will work. I used linqpad to quickly test code which has the Dump() extension method
Regex.Replace("test\r\ntest","\r\n","\n").Select(x => x).Dump();
Update : A regular replace also works BTW. You state that it doesn't?
"test\r\ntest".Replace("\r\n","\n").Select(x => x).Dump();
I have this bit of code below which saves perfectly fine to a text file, however there is no formatting that is transferred, for example, The below words would save as THISISATESTLAYOUT. I would like the desired output displayed below:
THIS
IS
A
TEST
LAYOUT
I know there's something obvious im missing here so thanks for any help
if (entity.Switch == true)
{
string path = #"filepath....\\Test.txt";
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.Write(entity.comments);
}
}
}
this string is saved in one entity called comments and displays fine within the C# application.
sw.Write and sw.WriteLine both give the same single line output with no spaces
and also entity.comments references a column in an SQL Server Table, and is a VARCHAR(MAX)
you may be using '\n' for newlines. If so use
sw.Write(entity.comments.Replace("\n", "\r\n"));
Change sw.Write to sw.WriteLine
I need help with adding a tab stop(position at 1cm) to a word document using word interop and c#. This is what i tried already.
Range range = paragraph.Range;
int firstTabStart = range .Start;
range .SetRange(firstTabStart, firstTabStart);
range .Paragraphs.TabStops.Add(5, WdTabAlignment.wdAlignTabRight);
When i open my word document i dont see any tab stops.
I can however insert tab alignments using
range .InsertAlignmentTab((int)WdAlignmentTabAlignment.wdCenter,
(int)WdAlignmentTabRelative.wdMargin);
Although, these tabs are absolute and I cannot edit them in the word document.
Please help.
I'm not able to reproduce the issue you're having, but I'm pasting the code I tested with so you can see if it differs any way from your existing code.
I saw tab stops appear in the ruler at 1 & 2 cm in every case:
Using either a .doc or .docx
Using paragraphs.TabStops instead of range.Paragraphs.TabStops
Using a blank document
Using a document with 1 or more paragraphs
Passing in 3rd argument for WdTabLeader in the TabStops.Add method.
And this was done in Word 2010
class Start
{
public static void Main()
{
// Open a doc file.
Application application = new Application();
Document document = application.Documents.Open(#"C:\Users\mmonkan\Documents\word.docx");
Paragraphs paragraphs = document.Paragraphs;
Paragraph paragraph = paragraphs[1];
Range range = paragraph.Range;
range.SetRange(0, 0);
range.Paragraphs.TabStops.Add(28, WdTabAlignment.wdAlignTabRight);
range.Paragraphs.TabStops.Add(56, WdTabAlignment.wdAlignTabRight);
// Close word.
application.Quit(WdSaveOptions.wdSaveChanges);
Console.ReadLine();
}
}
I am trying to replace bookmark in docx with text in c++\cli using open xml SDK concept.
The below piece of code will fetch bookmarks from word document and checks whether the bookmark matches the string “VERSION” if it is true, it is replaced with the string “0000” in the docx file.
Paragraph ^paragraph = gcnew Paragraph();
Run ^run = gcnew Run();
DocumentFormat::OpenXml::Wordprocessing::Text^ text = gcnew DocumentFormat::OpenXml::Wordprocessing::Text(“0000”);
run->AppendChild(text);
paragraph->AppendChild(run);
IDictionary<String^, BookmarkStart^> ^bookmarkMap =
gcnew Dictionary<String^, BookmarkStart^>();
for each (BookmarkStart ^bookmarkStart in
GlobalObjects::wordDoc->MainDocumentPart->RootElement->Descendants<BookmarkStart^>())
{
if (bookmarkStart->Name->Value == “VERSION”)
{
bookmarkStart->Parent->InsertAt<Paragraph^>(paragraph,3);
}
}
The above code works fine in most scenarios(wherever we insert bookmarks), but sometimes times it fails and I am not able to find the reason.
And if the bookmark is inserted at the starting position of a line, then after execution I am not able to open the docx file, there will be some errors.
I tried giving the index value as 0 for InserAt method even this is not working.
Please provide a solution for the above.
Thanks in advance
See How to Retrieve the Text of a Bookmark from an OpenXML WordprocessingML Document for code that retrieves text. It is written in C#, but you could use the code directly from C++/CLI.
See Replacing Text of a Bookmark in an OpenXML WordprocessingML Document for an algorithm that you can use to replace text.