I'm currently writing a program in C# that programmatically insert table in header/footer for MSWORD 2003.
My problem is after creation of table, there is unwanted space after the table. I have already manually fix or delete it using msword, but I cannot remove that extra space. Because of that the cursor was not start where the point of top margin is.
I've already google it but cannot find any solution. Any help will appreciate. Tnx
You can also set the Text Wrapping property of the table to AROUND instead of NONE. this will cause the following para mark to float to the right of the table, not below it, so you won't get the extra line, and you won't have to resort to 1 pt hacks (which work, but I try to avoid them when possible).
It's easy to do in Word manually, but A quick try at recording a macro to do it failed so I'm not sure of the Object Model method.
By default there is a new line after a table in MS Word. As a workaround you could try to set the font size after the table to 1.
Related
Me and my team recently changed from ITextSharp to PdfSharp, because of ITextSharp became really slow, and we couldn't seem to fix the problem.
But right now we have a problem, where our pdf, thats filled by PdfSharp, is 200kb bigger then the one from ITextSharp. The size itself isn't the problem, its that when we open our pdf in firefox, the data is still displayed fine in the viewer, but when we want to print it, all the multiline fields, is suddenly one liners, with a different font too.
We have /NeedAppearance on our acroform elements, and tried to remove it to see what it would look like in adobe, and etc. and it looked the same as it did on the print screen in firefox.
The NeedAppearance isn't on our document from the ITextSharp, and it displays fine in every viewer.
This is the code we use to set the text:
public static bool SetField(this PdfAcroForm form, string fieldName, string value)
{
PdfTextField field = (PdfTextField)form.Fields[fieldName];
if (field != null)
{
field.Text = value;
}
return field != null;
}
At the end of the fields being set, we have a document.flatten() to make the fields readOnly.
A little side note
Once we have opened the pdf in adobe, and we want to close it, it wants us to save it, without we have changed the document. Once we have saved it, it is 200kb less, and suddenly works in all viewers. This is with /NeedAppearance on.
Update 1
I've spend the whole night looking for a solution, but couldn't.
But this is what I have found so far:
On every PdfTextField after the Text property has been set, there comes an /AP element in Elements which contains a reference to an object, which contains what should be drawn.
I think that Adobe can understand the /NeedAppearance element on the acroforms, and therefore makes the /APelement on every field correct. The reason for the file is less kb after, is seams to be that Adobe do something with the streams on the elements, some sort of encoding, that takes off less space.
So as it is right now, I think I have too create a new Flatten method that creates the /AP elements right. I don't know why The current Flatten method doesn't do that, as it's only changing the fields to readonly.
What I ended up doing, is to create my own flatten method.
Summary of what the Flatten method do:
I've mad it an extension to PdfAcroForm.
I loop trough all the fields, except PdfChecboxfield, because that is displayed just fine.
Then I went and found the page the field was on, and created and XGraphics from that page.
Then I get the position and size of the field, from the element /Rect
Then putted my XGraphics in a XTextFormatter, and sets the appearance on my XTextFormmater by the elements of my field.
Then I use XTextFormatter.Drawstring() and after that, dispose my XGraphics.
Then to remove the field, I delete all the elements on that field.
If this was unclear to you, feel free to comment, and I'll try my best to help you.
DISCLAIMER:
The flatten method I created, will delete your fields, and you CAN NOT undo it. It writes the text on the pdf itself, but just do it on the fields position.
What I'm trying to do is insert, from a text box, into a MS Access database some text (no surprises). Thing is that after submitting what I have written, when I open the Access database it all appears as one string of text. So my question: is there a way in which I can determine the end of the text box per line so that when it reaches that point it would make a new line? Or something similar so that it would introduce a new line into the database file because this issue is very annoying.
P.S.: Yes the multiline option is enabled.
Thank you very much.
I believe you are trying to solve a non-problem. Quite possibly you'll find that you will want to show the same text in a number of different places within your application or even different applications (if it's not true now it MIGHT be true at some point in the future), so it should the the GUI to decide where and when break a text line, not your DB
You could either detect Environment.NewLine within the textbox's text, or you could use the Lines property to access each line individually.
I am using PDFSharp to export a table to PDF (using the regular MigraDoc.DocumentObjectModel.Tables.Table object). It works great except I ran into a few issues:
if the content of a single cell in the table is longer than the height of the page it seems like the content just gets cut off. A table itself can span multiple pages but a row seems like it can only be 1 page high and It seems like it doesn't extend onto the next page.
Is there any workaround to this or is this just a bug in the library?
Also for tables that span multiple pages, is there a way to have the header row on the table show up at the top of every page?
Re first question:
It's documented that MigraDoc does not break table rows over multiple pages. It's not a bug, it's a limitation. So it's up to you to design the tables that this does not cause problems.
IIRC there is a hack published on the PDFsharp forum that increases the page height to work around this problem. If you only need PDFfiles, this could be a workaround.
Edit: Didn't find the link when I made the post, but found it today when I tried again: Here's the workaround:
http://forum.pdfsharp.net/viewtopic.php?p=4311#p4311
I didn't try it myself.
Re second question:
Rows marked as header rows will be repeated on every new page. Just set the HeadingFormat property of those rows to true.
I am exporting some data to a PDF and I have been using iTextSharp with a lot of success, but I just hit a wall.
I have a group of information I need to keep on a single page. This information includes a handful of other Paragraph objects and tables. I can add 3 Paragraphs to another parent Paragraph and set that parent's KeepTogether property to true and everything works great.
When I add a PdfPTable to the Paragraph with KeepTogether set to true, the table disappears. No Exceptions or error messages, the table just disappears.
Any clue as to what is happening? Is there a work around? Should I be coding differently, like is there a better parent control than Paragraph to keep text and tables together on one page?
So I fixed the issue by approaching it a different way. Now I make sure to never set a KeepTogether property to true for paragraphs or tables.
Then, when I want a Paragraph that contains child paragraphs and PdfPTables, I add it to a one column, one cell, PdfPTable with its KeepTogether flag set to true.
So that works perfectly, just a little dirty.
I am working on a project in C# that will produce a Word document using the Word Automation API.
I would like to insert page breaks at specific points in the generated document and I am currently doing this successfully with the following code:
// Generate page break
object pageBreak = WdBreakType.wdPageBreak;
wordApp.Selection.InsertBreak(ref pageBreak);
However, if the document has naturally wrapped onto the next page anyway after running out of room on the previous page then I don't really want to be generating a page break or else I will end up with a blank page.
What I would really like is the ability to find out exactly where the cursor is and if it is on the first line and column of the current page then I can safely assume that it is not necessary to insert a page break.
Is there a way to access the position of the cursor? Or another solution that would do the same thing? It seems like a simple requirement so I apologize in advance if I have missed the obvious.
Assuming that you are programmatically building the document in a way that would cause wordApp.Selection to properly reflect your actual (and relevant) position in the document, you can determine its line and column on its starting page using its Information property and the following two WdInformation enums (shown here as VBA; not sure what the .NET PIA syntax is offhand):
line = wordApp.Selection.Information(wdFirstCharacterLineNumber)
col = wordApp.Selection.Information(wdFirstCharacterColumnNumber)
These values correspond to the Ln and Col values seen in Word's status bar. If they are both equal to 1, then you are in the first position of the page on which the Selection begins.
Good luck!
You could try setting property on the paragraph that causes it to have a page break before it. I don't if Word Automation API allows it to be set, but it seems exactly what you need.