Hello
My word document have some Comments .I want to transform this word document to pdf document .But I don’t want the Comments that appear in the pdf document.
Can you give me an example?
Thanks.
Another question.
For example,the word document like this:
……
Adress:__________
there is a bookmark in the underline.When I replace the bookmark, the underline will be long.How can I replace the bookmark with some word,but the underline maintain the original length.Like this:
……
Adress:xxxxx____
There has underline in the foot of the x.
- You can specify
LayoutOptions.CommentDisplayMode
to control how comments are rendered. In your case you can useCommentDisplayMode.Hide
to hide comments upon rendering document to PDF:
Document doc = new Document("C:\\Temp\\in.docx");
doc.LayoutOptions.CommentDisplayMode = CommentDisplayMode.Hide;
doc.Save(@"C:\Temp\out.pdf");
- There are several ways to achieve what you need. The easiest one is using table. Please see the following tempalate:
in.docx (12.8 KB)
Document doc = new Document("C:\\Temp\\in.docx");
doc.Range.Bookmarks["test"].Text = "This is some text";
doc.Save(@"C:\Temp\out.docx");
Here is the output: out.docx (10.2 KB)
Underline is emulated by the bottom cell border.
The number 2 question,Can I control by code?Can you give me an example.The word document style can’t be changed.
@JohnKj It depend on your template. It is difficult to say without looking at your real document. If I understand properly there is is underlined whitespaces in your template a a bookmark before them. If so I am afraid it would be difficult to achieve what you need. Please attach your sample template here for our reference.
@JohnKj The only way to achieve this with your template is using floating shapes, i.e. put a floating shape with the value at the bookmark location. Please see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Use LayoutCollector and LayoutEnumerator to determine coordinates of bookmakrs.
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
foreach (Bookmark bk in doc.Range.Bookmarks)
{
enumerator.Current = collector.GetEntity(bk.BookmarkStart);
RectangleF rect = enumerator.Rectangle;
// Create shape and put it on the detected coordinates.
builder.MoveToBookmark(bk.Name);
Shape s = builder.InsertShape(ShapeType.TextBox, 100, rect.Height);
s.WrapType = WrapType.None;
s.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
s.RelativeVerticalPosition = RelativeVerticalPosition.Page;
s.Top = rect.Y;
s.Left = rect.X;
// Remove inner margins.
s.TextBox.InternalMarginBottom = 0;
s.TextBox.InternalMarginLeft = 0;
s.TextBox.InternalMarginRight = 0;
s.TextBox.InternalMarginTop = 0;
// Disable borders
s.Stroked = false;
// Disable fill.
s.Filled = false;
// Put value
builder.MoveTo(s.FirstChild);
builder.Write("This is some value");
}
doc.Save(@"C:\Temp\out.docx");
Assume,The bookmarks which created are not very standardized.
For exmaple,like the image
1 is MarkA start position,2 is MarkB start position.Below is the format of the replaced bookmarks what I want.
That means the replace texts will be in the right position.Not like below.
Can you give me an example? Thanks.
@JohnKj I am afraid without standardization of the template there is no way to provide a general solution for all cases. I would suggest you to update your templates and use the approach suggested in my first reply.
I see,Thank for your help