PPTX OpenXML - Which is the newline indicator in bulleted text? - powerpoint

Can you please help me identify which is the newline indicator in bulleted text in
PPTX OpenXML ? based on this I want add newline character in my program
-Thank you

Use the Break Class
So for the following slide with bulleted list with a newline indicator:
Refer to the follwing code snipping showing from third bullet to fourth:
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml;
using A = DocumentFormat.OpenXml.Drawing;
...
A.Run run3 = new A.Run();
A.RunProperties runProperties3 = new A.RunProperties(){ Language = "en-US", Dirty = false, SpellingError = true, SmartTagClean = false };
A.Text text3 = new A.Text();
text3.Text = "Th";
run3.Append(runProperties3);
run3.Append(text3);
A.Run run4 = new A.Run();
A.RunProperties runProperties4 = new A.RunProperties(){ Language = "en-US", Dirty = false, SmartTagClean = false };
A.Text text4 = new A.Text();
text4.Text = "";
run4.Append(runProperties4);
run4.Append(text4);
A.Break break1 = new A.Break();
A.RunProperties runProperties5 = new A.RunProperties(){ Language = "en-US", Dirty = false, SmartTagClean = false };
break1.Append(runProperties5);
A.Run run5 = new A.Run();
A.RunProperties runProperties6 = new A.RunProperties(){ Language = "en-US", Dirty = false, SpellingError = true, SmartTagClean = false };
A.Text text5 = new A.Text();
text5.Text = "ird";
run5.Append(runProperties6);
run5.Append(text5);
A.EndParagraphRunProperties endParagraphRunProperties1 = new A.EndParagraphRunProperties(){ Language = "en-US", Dirty = false, SmartTagClean = false };
paragraph3.Append(paragraphProperties3);
paragraph3.Append(run3);
paragraph3.Append(run4);
paragraph3.Append(break1);
paragraph3.Append(run5);
paragraph3.Append(endParagraphRunProperties1);
This code was generated with the Open XML Productivity Tool. I highly recommend you use it to reverse engineer the things you need to write code for in Excel, Word and PowerPoint.
Hope this helps...

Related

Indesign conditional text styling using ExtendScript

Does anyone know if it's possible to style text a certain way using ExtendScript, only when a certain condition is met for the paragraph in question?
I've cobbled together an ExtendScript script that I use in InDesign to fix text styles when they aren't fixed properly by the Paragraph Style tool, and it works well so far - changing Courier and Arial Unicode text to Times New Roman and fixing the font size - but i would really like to include a function that changes Times New Roman Italic to Times New Roman Bold Italic - but ONLY when the paragraph it appears in has a first letter that is set in Univers. Is there a way I can include an 'if' statement that will only trigger this style change in those circumstances?
Here's my existing code:
var mydoc = app.activeDocument;
var theFontSize = [
'Courier New','16','Courier New','8.75',
'Times New Roman','16','Times New Roman','8.75',
];
for (i = 0; i < (theFontSize.length/4); i++) {
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedFont = theFontSize[i*4];
if (theFontSize[(i*4)+1] != ''){
app.findTextPreferences.pointSize = theFontSize[(i*4)+1];
};
app.changeTextPreferences.appliedFont = theFontSize[(i*4)+2];
if (theFontSize[(i*4)+3] != ''){
app.changeTextPreferences.pointSize = theFontSize[(i*4)+3];
};
mydoc.changeText();
};
var theFontReplacements = [
'Courier New','Regular','Times New Roman','Regular',
'Courier New','Italic','Times New Roman','Italic',
'Courier New','Bold','Times New Roman','Bold',
'Courier New','Bold Italic','Times New Roman','Bold Italic',
'Courier New','75 Black','Univers','75 Black',
'Arial Unicode MS','Regular','Times New Roman','Regular',
];
for (i = 0; i < (theFontReplacements.length/4); i++) {
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedFont = theFontReplacements[i*4];
if (theFontReplacements[(i*4)+1] != ''){
app.findTextPreferences.fontStyle = theFontReplacements[(i*4)+1];
};
app.changeTextPreferences.appliedFont = theFontReplacements[(i*4)+2];
if (theFontReplacements[(i*4)+3] != ''){
app.changeTextPreferences.fontStyle = theFontReplacements[(i*4)+3];
};
mydoc.changeText();
};
app.findTextPreferences = NothingEnum.nothing;
app.changeTextPreferences = NothingEnum.nothing;
This should get you started. It will be slower than using changeText, but I don’t think you can do what you’re asking with changeText.
// Change applied font of text set in Times New Roman Italic in paragraphs whose first character is set in Univers to Times New Roman Bold Italic
app.findTextPreferences.appliedFont = 'Times New Roman';
app.findTextPreferences.fontStyle = 'Italic';
var foundItems = app.activeDocument.findText(); // Set foundItems to all results of search according to app.findTextPreferences
for (var i = 0; i < foundItems.length; i++) { // For each result found
var item = foundItems[i];
if (item.paragraphs[0].characters[0].appliedFont.name.indexOf('Univers') == 0) { // If item’s first enclosing paragraph’s first character’s font name starts with “Univers”
item.appliedFont = 'Times New Roman\tBold Italic'; // Set item’s font to Times New Roman italic
}
};

Customizing DecimalRow Text Color

I am trying to change the text color of DecimalRow. Neither the tintColor nor textColor attributes on cell.textField seem to do anything:
<<< DecimalRow(){
$0.tag = "final";
$0.useFormatterDuringInput = true
let formatter = CurrencyFormatter()
formatter.locale = .current
formatter.numberStyle = .currency
$0.formatter = formatter
}.cellSetup({ (cell, row) in
cell.textField.textColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
cell.textField.tintColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
})
Try with cellUpdate closure instead, it works, look at the picture below
<<< DecimalRow(){
$0.tag = "final";
$0.useFormatterDuringInput = true
let formatter = CurrencyFormatter()
formatter.locale = .current
formatter.numberStyle = .currency
$0.formatter = formatter
}.cellUpdate({ (cell, row) in
cell.textField.textColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
cell.textField.tintColor = UIColor(red:0.15, green:0.55, blue:0.16, alpha:1.0)
})
I hope this helps you, best regards

How can I add disparate chunks to a PdfPCell using iTextSharp?

How can I concatenate disparate chunks and add them to a paragraph, the paragraph to a cell, then the cell to a table using iTextSharp (in generating a PDF file)?
I am able to get to a certain "place" in my PDF file generation, so that it looks like so (the right side of the page is blank, as it should be):
This is the code I'm using for that:
using (var ms = new MemoryStream())
{
using (var doc = new Document(PageSize.A4, 50, 50, 25, 25))
{
//Create a writer that's bound to our PDF abstraction and our stream
using (var writer = PdfWriter.GetInstance(doc, ms))
{
//Open the document for writing
doc.Open();
var courierBold11Font = FontFactory.GetFont(FontFactory.COURIER_BOLD, 11, BaseColor.BLACK);
var docTitle = new Paragraph("Mark Twain", courierBold11Font);
doc.Add(docTitle);
var timesRoman9Font = FontFactory.GetFont("Times Roman", 9, BaseColor.BLACK);
var subTitle = new Paragraph("Roughing It", timesRoman9Font);
doc.Add(subTitle);
var courier9RedFont = FontFactory.GetFont("Courier", 9, BaseColor.RED);
var importantNotice = new Paragraph("'All down but nine; set 'em up on the other alley, pard' - Scotty Briggs", courier9RedFont);
importantNotice.Leading = 0;
importantNotice.MultipliedLeading = 0.9F; // reduce the width between lines in the paragraph with these two settings
PdfPTable table = new PdfPTable(1);
PdfPCell cellImportantNote = new PdfPCell(importantNotice);
cellImportantNote.BorderWidth = PdfPCell.NO_BORDER;
table.WidthPercentage = 50;
table.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cellImportantNote);
doc.Add(table);
doc.Close();
}
var bytes = ms.ToArray();
String PDFTestOutputFileName = String.Format("iTextSharp_{0}.pdf", DateTime.Now.ToShortTimeString());
PDFTestOutputFileName = PDFTestOutputFileName.Replace(":", "_");
var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), PDFTestOutputFileName);
File.WriteAllBytes(testFile, bytes);
MessageBox.Show(String.Format("{0} written", PDFTestOutputFileName));
}
}
However, I need to break up the red text so that part of it is bolded, parts of it are anchor tags/hrefs, etc.
I thought I could do it this way:
var courier9RedBoldFont = FontFactory.GetFont(FontFactory.COURIER_BOLD, 9, BaseColor.RED);
// Build up chunkified version of "important notice"
Chunk boldpart = new Chunk("All down but nine - set 'em up on the other alley, pard", courier9RedBoldFont);
Chunk attribution = new Chunk("Scotty Briggs", courier9RedFont);
PdfPTable tbl = new PdfPTable(1);
tbl.WidthPercentage = 50;
tbl.HorizontalAlignment = Element.ALIGN_LEFT;
var par = new Paragraph();
par.Chunks.Add(boldpart);
par.Chunks.Add(attribution );
PdfPCell chunky = new PdfPCell(par);
chunky.BorderWidth = PdfPCell.NO_BORDER;
tbl.AddCell(chunky);
doc.Add(tbl);
...but that's not adding anything at all to the PDF file, but why not? Doesn't a cell take a paragraph, and cannot a paragraph be comprised of Chunks?
Instead of para.Chunks.Add() just use par.Add(); The Chunks that are returned from Paragraph actually come from the base class Phrase. If you look at the code for that property you'll see that the collection returned is actually a temporary collection created on the fly so it is effectively read-only.

Photoshop scripting mantain same file name and whitespace

I'm trying to add a layer to some images and then save them.
The problem is that many images have whitespace in the name. When I try to save the whitespaces are replaced with "-", but I want mantain the same name.
For example an image called "Google Analytics.png" become "Google-Analytics.png". But I need to preserve the name without that extra "-".
My code:
function SavePNG(saveFile){
var file = new File(saveFile);
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = false;
pngOpts.interlaced = false;
pngOpts.quality = 100;
$.writeln(file)
app.activeDocument.exportDocument(file,ExportType.SAVEFORWEB,pngOpts);
}
Try using saveAs instead of exportDocument; it'll respect the name of the file you give it. The options are yours to change:
var myfile = "C:\\temp\\Google Analytics.png";
SavePNG(saveFile)
function savePNG(saveFile)
{
// save out the image
var pngFile = new File(filepath);
pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.embedColorProfile = true;
pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
pngSaveOptions.matte = MatteType.NONE;
pngSaveOptions.quality = 1;
activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
}

Exporting to excel when there are special characters in the data ( French descriptions)

I am exporting data to excel file using Excel query table. There will be a text file with the data containing many rows, each cell is separated by | character. I am dumping the data to excel file using the following code
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = false;
oXL.UserControl = false;
//Get a new workbook.
oWBook = (Excel._Workbook)(oXL.Workbooks.Open(strFilename, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false));
oSheet = (Excel._Worksheet)oWBook.ActiveSheet;
oSheet.Activate();
//Create header row 2
oXL.ReferenceStyle = Microsoft.Office.Interop.Excel.XlReferenceStyle.xlR1C1;
Excel.Range oRange2 = oSheet.get_Range("A2", "A2");
oRange2.FormulaR1C1 = HeaderLine1;
//Create header row 2
oRange2 = oSheet.get_Range("A3", "A3");
oRange2.FormulaR1C1 = HeaderLine2;
oRange2 = oSheet.get_Range("A" + StartRowNumber.ToString().Trim(), Missing.Value);
var temp = oSheet.QueryTables.Add("TEXT;" + TextFileName, oRange2, Missing.Value);
temp.Name = TextFileName.ToUpper().Replace(".TXT", "");
temp.PreserveFormatting = true;
temp.AdjustColumnWidth = false;
temp.TextFileStartRow = 1;
temp.TextFileParseType = Microsoft.Office.Interop.Excel.XlTextParsingType.xlDelimited;
temp.TextFileTextQualifier = Microsoft.Office.Interop.Excel.XlTextQualifier.xlTextQualifierDoubleQuote;
temp.TextFileConsecutiveDelimiter = false;
temp.TextFileTabDelimiter = true;
temp.TextFileSemicolonDelimiter = false;
temp.TextFileCommaDelimiter = false;
temp.TextFileSpaceDelimiter = false;
temp.TextFileOtherDelimiter = "|";
temp.TextFilePlatform = 1252;//65001;//1252;//65001;//1200;
//http://en.wikipedia.org/wiki/Code_page
temp.TextFileColumnDataTypes = GetDataType(ColumnDataType);
temp.TextFileTrailingMinusNumbers = true;
temp.Refresh(false);
//temp.Connection.ToString();
temp.Delete();
oXL.ReferenceStyle = Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1;
oWBook.Save();
oWBook.Close(false, Missing.Value, Missing.Value);
}
catch (Exception ex)
{
oWBook.Close(false, Missing.Value, Missing.Value);
}
finally
{
oXL.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(oSheet);
oSheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWBook);
oWBook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oXL);
oXL = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
When the text file contains some special characters( Ex French words) it will not display as they are when the excel file is opened after generating....
Can anyone help to solve this problem ?
Thanks
Suresh

Resources