I'm using http://powertools.codeplex.com and/or http://docx.codeplex.com to join word documents.
The first document contains a footer, the second document does not.
The joined document shows the footer on both pages/sections.
How can I remove the footer of the second section?
The footer of the second section is connected to the preceding section.
How can this connection be removed by using OpenXML 2.0? In Word this is no problem.
My source code can be found here:
http://dl.dropbox.com/u/21096596/OpenXML.zip
I found a solution how the footer of the follow-up sections could be replaced:
MainDocumentPart myPart = document.MainDocumentPart;
FooterPart newFtPart = myPart.AddNewPart<FooterPart>();
string ft_ID = myPart.GetIdOfPart(newFtPart);
new DocumentFormat.OpenXml.Wordprocessing.Footer().Save(newFtPart);
foreach (SectionProperties sectProperties in myPart.Document.Descendants<SectionProperties>().Skip(1))
{
FooterReference newFtReference =
new FooterReference() { Id = ft_ID, Type = HeaderFooterValues.Default };
sectProperties.Append(newFtReference);
}
Related
I'm designing a BIRT report that should print on a form. In this report it is printing in both sides so the client is asking to do a Page Break if the details of a WorkOrder ends in a odd number so both WorkOrders wouldnt be in the same sheet.
Is it possible to add a pagecount() and do a page break if it is the end of the work order an its an odd number?
Thanks in advance.
I only have part of the answer. It would be possible on the adding pagination in the beforeFactory on the ReportDesign section. Out of the box Maximo reports have a pagination statement for PDF's. You can extend the if statement - see example of OOTB code below.
You would need to be able to bring back the WO number as a global parameter. That part is what you would need to do some additional research on.
if ( (reportContext.getParameterValue("usepagebreaks") == "false")|| reportContext.getOutputFormat() == "pdf" ) {
// Give each table in the report a name, and add the names to the list below, e.g. ["mainTable", "childTable1"]
var tableListing = ["dataSet_inventory_id13#"];
for each(var tableName in tableListing) {
var table = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement(tableName)
if (table != null) {
table.setProperty("pageBreakInterval", 0);
}
}
}
My code below is lost when opening PDF file which has only one column on the front page and more than 1 column on other pages.
Someone can tell me what I'm doing wrong?
Below my code:
PdfReader pdfreader = new PdfReader(pathNmArq);
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
for (int page=1; page <= lastPage; page++)
{
extractText = PdfTextExtractor.GetTextFromPage(pdfreader, page, strategy);
extractText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(extractText)));
/ / ...
}
You use the SimpleTextExtractionStrategy. This strategy assumes that the text drawing instructions in the PDF are sorted by the reading order. In your case that does not seem to be the case.
If you cannot count on the PDF containing drawing operations in reading order but are only using iText text extraction strategies from the distribution, you have to know areas which constitute a single column. If a page contains multiple columns, you have to use RegionTextRenderFilter to restrict to a column and then use the LocationTextExtractionStrategy.
PS: What exactly is your intention in that
extractText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(extractText)));
line?
I have a dynamically generated docx file.
Need write the text strictly to end of page.
With Microsoft.Interop i insert Paragraphs before text:
int kk = objDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref wMissing);
while (objDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref wMissing) != kk + 1)
{
objWord.Selection.TypeParagraph();
}
objWord.Selection.TypeBackspace();
But i can't use same code with Open XML, because pages.count calculated only by word.
Using interop impossible, because it so slowwwww.
There are 2 options of doing this in Open XML.
create Content Place holder from Microsoft Office Developer Tab at the end of your document and now you can access this Content Place Holder programatically and can place any text in it.
you can append text driectly to your word document where it will be inserted at the end of your text. In this approach you got to write all the stuff to your document first and once you are done than you can append your document the following way
//
public void WriteTextToWordDocument()
{
using(WordprocessingDocument doc = WordprocessingDocument.Open(documentPath, true))
{
MainDocumentPart mainPart = doc.MainDocumentPart;
Body body = mainPart.Document.Body;
Paragraph paragraph = new Paragraph();
Run run = new Run();
Text myText = new Text("Append this text at the end of the word document");
run.Append(myText);
paragraph.Append(run);
body.Append(paragraph);
// dont forget to save and close your document as in the following two lines
mainPart.Document.Save();
doc.Close();
}
}
I haven't tested the above code but hope it will give you an idea of dealing with word document in OpenXML.
Regards,
I have multiple tables in a word template and need to change each of it in an other way. Also it is possible that one or the other will be deleted or inserted so I can't say I take the 5th and that's always the same one.
The identification has to be saved so I can't use the .ID value.
What way is there to identify a specific table with VSTO? Preferable one which can also be set in the document without VSTO.
I found a way to do it:
Mark the table in word and add a bookmark to it. You have to choose a unique name so you can also identify the table. The identification can be done with a method like the following:
public Word.Bookmark GetBookmark(String bookmarkName)
{
// Find bookmark
Word.Bookmark bookmark = null;
foreach (Word.Bookmark curBookmark in Globals.ThisDocument.Bookmarks)
{
if (curBookmark.Name.Equals(bookmarkName))
{
bookmark = curBookmark;
break;
}
}
return bookmark;
}
I ran into similar problem. To solve the problem I set title of the table in word tamplate(Right click table->Table Properties...->Alt text->Title) and search all the table in word document for the title. Below is the code I used to search the table.
public static Table getTable(Document doc, String title){
int totalTables = doc.Tables.Count;
Microsoft.Office.Interop.Word.Table ret = null;
for (int i = 1; i <= totalTables; i++){
if (title.Equals(doc.Tables[i].Title, StringComparison.OrdinalIgnoreCase)){
ret = doc.Tables[i];
break;
}
}
return ret;
}
Is it possible to use alternative text for the tables as identifier?
Use the below code to retrieve them (code copied from here)
Word.Application wdApp = Application;
Word.Document wdDoc = wdApp.ActiveDocument;
Word.Table wdTable = wdDoc.Tables[1];
MessageBox.Show(wdTable.Title + "\n" + wdTable.Descr);
I used the code in the link mentioned below to merge word files into a single file
http://devpinoy.org/blogs/keithrull/archive/2007/06/09/updated-how-to-merge-multiple-microsoft-word-documents.aspx
However, seeing the output file i realized that it was unable to copy header image in the first document. How do we merge documents preserving format and content.
I will suggest to use GroupDocs.Merger Cloud for merging multiple word document to a single word document, it keeps the formatting and contents of the source documents. It is a platform independent REST API solution without depending on any third-party tool or software.
Sample C# code:
var configuration = new GroupDocs.Merger.Cloud.Sdk.Client.Configuration(MyAppSid, MyAppKey);
var apiInstance_Document = new GroupDocs.Merger.Cloud.Sdk.Api.DocumentApi(configuration);
var apiInstance_File = new GroupDocs.Merger.Cloud.Sdk.Api.FileApi(configuration);
var pathToSourceFiles = #"C:/Temp/input/";
var remoteFolder = "Temp/";
var joinItem_list = new List<JoinItem>();
try
{
DirectoryInfo dir = new DirectoryInfo(pathToSourceFiles);
System.IO.FileInfo[] files = dir.GetFiles();
foreach (System.IO.FileInfo file in files)
{
var request_upload = new GroupDocs.Merger.Cloud.Sdk.Model.Requests.UploadFileRequest(remoteFolder + file.Name, File.Open(file.FullName, FileMode.Open));
var response_upload = apiInstance_File.UploadFile(request_upload);
var item = new JoinItem
{
FileInfo = new GroupDocs.Merger.Cloud.Sdk.Model.FileInfo
{ FilePath = remoteFolder + file.Name }
};
joinItem_list.Add(item);
}
var options = new JoinOptions
{
JoinItems = joinItem_list,
OutputPath = remoteFolder + "Merged_Document.docx"
};
var request = new JoinRequest(options);
var response = apiInstance_Document.Join(request);
Console.WriteLine("Output file path: " + response.Path);
}
catch (Exception e)
{
Console.WriteLine("Exception while Merging Documents: " + e.Message);
}
That code is inserting a page break after each file.
Since sections control headers, if a second or subsequent document has a header, you'll probably be wanting to keep the original section properties, and insert those after your first document.
If you look at your original document as a docx, you'll probably see that your section is a document level section properties element.
The easiest way around your problem may be to create a second section properties element inside the last paragraph (which contains the header information). Then this should just stay there when the documents are merged (ie other paragraphs added after it).
That's the theory. See also http://www.pcreview.co.uk/forums/thread-898133.php
But I haven't tried it; it assumes InsertFile behaves as I expect it should.