How can I add text to a document footer using OpenXML? - openxml

I have a document template that I want to append some text to the footer. I've seen ways of deleting the footer to replace it, and ways to replace text in the footer, but I want to keep the footer as is from the template and just add to it. I have code to add text to the main doc., but unfortunately, main doc. parts are not setup the same way as footer parts. This is easily accomplished in Interop by a range.InsertAfter(text), but end users need this to work sans Word.
FooterPart footer = _doc.MainDocumentPart.FooterParts.ElementAtOrDefault(0);
string rid = _doc.MainDocumentPart.GetIdOfPart(footer);
footer = _doc.MainDocumentPart.AddNewPart<FooterPart>(rid);
Paragraph para = footer.AddPart(new Paragraph(), rid);
Run run = para.AppendChild(new Run());

// get the last footer of the document
FooterPart footerPart = _doc.MainDocumentPart.FooterParts.LastOrDefault();
// create your paragraph. i created simple, but you will need to add style properties to the run or text class
Paragraph pr = new Paragraph(new Run(new Text("hello")));
// Insert the Paragraph to the end of the footer in footerPart.Footer
footerPart.Footer.AppendChild(pr);
Other way as you said would be putting a text to replace like "txttoreplace" and then you will find it and replace
IEnumerable<FooterPart> footerPartsList = Documento.MainDocumentPart.FooterParts.ToList();
foreach (FooterPart hp in footerPartsList)
foreach (Text text in hp.RootElement.Descendants<Text>())
{
if (text.Text.Contains("txttoreplace"))
{
text.Text = text.Text.Replace("txttoreplace", "new text");
}
}
And another way and the hardest would be, you inser the whole footer, with open xml productivity tools you get the c# code of the footer.xml, and then you delete the footer of the document and you insert.

Related

Typo3 Content Elements missing in wizard

I have some content elements in a site package which I want to show up in the content element wizard as explained here:
https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentElements/ContentElementsWizard.html
Basically I have done the same as shown in the section "Create a new tab"
Configuration\TsConfig\Page\ContentElement\All.tsconfig is looking like this:
mod.wizards.newContentElement.wizardItems.mci.header = MCI
mod.wizards.newContentElement.wizardItems.mci {
elements {
mci_home_banner {
iconIdentifier = home-banner
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
mci_home_banner_element {
iconIdentifier = home-banner-element
title = Home Banner Element
description = Element im Starseitenbanner
tt_content_defValues.CType = mci_home_banner_element
}
}
show := addToList(mci_home_banner, mci_home_banner_element)
}
I reduced the code to just 2 elements. They are not shown at all, but are available over the dropdown, so I can switch to one of them after choosing another element.
This didn't work when created in 9.5 and still does not work after switching to version 11.5.10
What am I missing?
#user414873 Did you try to add your custom elements to the "common" tab instead of your new one "mci"?
And did you try to use an existing icon identifier (e.g. "content-image" or an other one - see https://typo3.github.io/TYPO3.Icons/)? Just to make sure that there is no problem with your custom icons that prevents the elements from being displayed.
Does this minimal example work for you:
mod.wizards.newContentElement.wizardItems.common {
elements {
mci_home_banner {
iconIdentifier = content-image
title = Home-Banner
description = Banner der Startseite
tt_content_defValues.CType = mci_home_banner
}
}
show := addToList(mci_home_banner)
}
And I would doubt this:
I guess otherwise the content elements wouldn't be available at all.
I suggest you check it's correctly included by using the "Info" module in your TYPO3 main menu. Then select the page where the content element should be included and switch the dropdown on top of the content area to "View TSconfig fields content". Now you can search for "wizards" and check if your element is included.

How to show complete header label name in Select Columns header menu dialog(Column Chooser),when header column labels contain new line character?

I've header menu configuration added in my nat table as follows,where I've included "Select Columns" menu as well:
// Popup menu
this.natTable.addConfiguration(new HeaderMenuConfiguration(this.natTable) {
#Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable) .withColumnChooserMenuItem(); }
});
// Column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler( bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), columnHeaderLayer.getColumnHeaderLayer(), columnHeaderLayer.getColumnHeaderDataLayer(), columnHeaderLayer.getColumnGroupHeaderLayer(), columnGroupModel);
//If header name consists of multiple words then I've used ("\n") as a separator between words in
//the header column name ,so that some space could be saved
// In that case on opening "Select Columns" context menu dialog only first word of column is visible
Can it be fixed by replacing all "\n" and white space character by single white space(" ") character in
In org.eclipse.nebula.widgets.nattable.columnChooser.gui.ColumnChooserDialog
//code to replace extra white spaces or new line character from column label with single space so that //header name is completely visible in populate tree method
treeItem.setText(columnEntry.getLabel());
In that case can fix be provided to replace extra space with single space in column header name or is there any other alternative to fix it?
Image with header names having multiple words For eg:"Issue Date",if header name is dispalyed as "Issue\nDate",only Issue is visible in "Select Columns" context menu dialog
IIRC you add the line breaks to save some space. They are not needed for any semantical reason. I would suggest to configure the TextPainter that renders the column header cell content to wrap automatically if not enough space is available. This could look like this for example:
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new BeveledBorderDecorator(new TextPainter(true, false, false, true)),
DisplayMode.NORMAL,
GridRegion.COLUMN_HEADER);

Handle paragraphs in swift

Is there a recommended way of handling paragraphs in swift? I am very new to swift so I'm not sure what the recommended solution or any solution for that matter is.
I want to be able to open a .txt file and be able to select a paragraph, selecting the paragraph needs to print the selected paragraph to a label.
I haven't got any code for this yet, other than opening and viewing the text file by doing the following:
let file = "/Users/wade/Desktop/ht.txt"
let path=URL(fileURLWithPath: file)
let text=try! String(contentsOf: path)
textView.stringValue = text
Once the .txt file is displayed I want to be able to click on a paragraph and have the paragraph display in a separate label
I am not fixed on using .txt files if there is a better format for achieving this
I'm guessing that printing to the label should be as easy as
let selectedParagraph = //however we identify the paragraph stringvalue
let thelabel = selectedParagraph.stringValue
But I need to know how to identify and get the text from the paragraph
Create a subsclass of NSTextView and use it to display the whole text. This will always select text by paragraph:
class ParagraphTextView: NSTextView {
override func selectionRange(forProposedRange proposedCharRange: NSRange,
granularity: NSSelectionGranularity) -> NSRange {
return super.selectionRange(forProposedRange: proposedCharRange,
granularity: .selectByParagraph)
}
}
Then set a delegate (NSTextViewDelegate) and track selection changes of the text view to update your secondary label with the current selection.

iText(Sharp) - how to avoid creating a blank page?

I'm generating a PDF document using iTextSharp version 5.5.7, using their "streaming" mode - by which I mean I'm not specifying the location of every piece of text, I'm just adding Paragraphs to the Document and letting iTextSharp figure out where to draw them. The text I'm outputting is the result of a report generator, so it is different every time.
The problem I'm running into is this: imagine that, given the page size and the selected font, I can fit 40 lines of text on a page. I output 40 Paragraphs, then I output a blank Paragraph (contents=" "), then an image that fills an entire page. iTextSharp does exactly what I tell it - I end up with one page full of text, a blank page, and then a page containing my image.
But now my document looks funny - there is this unexpectedly blank page in the middle of everything.
I can't just say "don't output any blank lines" because of course that blank line might show up after only 20 lines of text, in which case it has to be there. I need some way to either tell iTextSharp "include this paragraph only if it's not the only thing on a page" or else somehow detect that the page is blank in OnEndPage() and suppress its output (without screwing up my page numbers).
Any suggestions on how I can do this?
ADDED LATER
Output from the report generator:
<html>
<p>Information header</p>
<p>Detail</p>
<p>Detail</p>
<p>Detail</p>
<p></p> <!-- Blank line inserted by report generator for clarity -->
<p>Information header</p>
<p>Detail</p>
<p>Detail</p>
<p>Detail</p>
...
<p>Detail</p> <!-- just by random happenstance this is the last line that will fit on the first page -->
<p></p> <!-- This line happens to be blank, I have no control over it -->
<img src="blah blah"></image>
My (pseudo) code:
foreach (HtmlNode node in htmlFromReportGenerator)
{
if (node is text)
pdfDoc.Add(new Paragraph(node.text));
else if (node is image)
pdfDoc.Add(new Image(node.image));
}
Following Bruno's suggestion, my (pseudo)code now looks like this:
Paragraph lastParagraph = null;
foreach (HtmlNode node in htmlFromReportGenerator)
{
if (node is text)
{
Paragraph parg = new Paragraph(node.text);
if ( (lastParagraph != null) && (text.Trim().Length == 0) )
lastParagraph.SpacingAfter += parg.Leading;
else
{
pdfDoc.Add(parg);
lastParagraph = parg;
}
}
else if (node is image)
{
pdfDoc.Add(new Image(node.image));
lastParagraph = null;
}
}

Change text in a textbox in Powerpoint slide

I have a Powerpoint presentation which contains 3 slides. Each slide has a Textbox which is a place holder. I would like to replace the Textbox contents on one slide.
I need to know how to do this using C# and OpenXML
Thanks a ton
Do this for each slide, you want to change:
ODP.ShapeTree tree = slide.Slide.CommonSlideData.ShapeTree;
foreach (ODP.Shape shape in tree.Elements<ODP.Shape>())
{
// Run through all the paragraphs in the document
foreach (ODD.Paragraph paragraph in shape.Descendants().OfType<ODD.Paragraph>())
{
foreach (ODD.Run run in paragraph.Elements<ODD.Run>())
{
if (run.Text.InnerText.Contains("PLACEHOLDER"))
{
run.Text = new ODD.Text("Your new text");
}
}
}
}
Keep in mind, that if your template's placeholders contain spaces, this may create two individual run elements. So instead of one run element with run.Text of "Place holder", you might get one run with run.text of "Place" and another one with run.Text "holder".