openxml merge documents using altChunk and use destination paragraph format - c#

I have a template.docx, doc1.docx, doc2.docx. I am trying to merge doc1.docx and doc2.docx into template.docx using altChunk. The 3 documents have different font size and font styles. I want the resulting document base on the style in template.docx. Any ideas how to achieve that?
For example:
all the heading1 font size is 24, font color is blue
List paragraph font size is 12, font family is Times New Roman

Related

Issue with "native" color for font symbols

I have an issue with an embbeded font in my iText7 program concerning the rendered color of the text. Let me show you:
Here is the font. When I use this font in word, I can do the following by entering "aaaddd":
So here is my code:
using iText.Kernel.Pdf;
using iText.Layout.Element;
using iText.Layout;
using ConsoleApp1.Properties;
using iText.IO.Font;
using iText.Kernel.Font;
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.pdf";
var symbol = PdfFontFactory.CreateFont(Resources.swsymbolsFRcolor_Regular, PdfEncodings.WINANSI, PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED);
var writer = new PdfWriter(path);
var pdf = new PdfDocument(writer);
var document = new Document(pdf);
var paragraph1 = new Paragraph("aaaddd");
paragraph1.SetFont(symbol);
document.Add(paragraph1);
document.Close();
The problem is that the generated symbols are in black and white:
Using Word, sometimes, I found a similar behavior. I have to set the color to "auto" to restore the "native" color of the symbols:
But I can't find any "auto" or "native" color in the iText7 SDK.
There are several other fonts that do the same things, but none of those I tried worked.
PDF fonts are generally monochrome by definition as a vector with flag to fill so by default all are black, you can individually set a font fill colour different to the outer stroke (as shown below) for "ASDAaaaddd" but its "unexpected".
These characters were place as default black then the group edited, so for your example they would need to be two groups.
PDF was designed before SVG fonts WOOF or emojis so coloured characters are best added as html vectors then reprinted as pdf equivalent objects.
Don't forget to embed the font but that font did not embed in my test, however it does say its editable ?

Adding different text formats like (Bold, Underline, color, etc) inside DrawString, PDFSharp

I need to change the DrawString paragraph into different file formats like (Bold, Underline, color, etc).
Eg: Hi, This is RAM,
gfx.DrawString("Hi, This is RAM", fontRegular, XBrushes.DarkSlateGray, 0, 30);
You can use DrawString with regular, bold, italic, and bold italic fonts.
There are no paragraphs with PDFsharp. Just make the appropriate calls to DrawString with the right fonts and the correct positions. With your example, you need three calls to DrawString. Use MeasureString to find how much space a string needs so you can draw the next string at the correct position.
MigraDoc uses PDFsharp to create PDF files. MigraDoc has paragraphs and using AddFormattedText you can mix several fonts and font styles in one paragraph. So maybe consider using MigraDoc.
Information about MigraDoc on the PDFsharp web site:
http://pdfsharp.net/Overview.ashx

How to obtain DPI equivalent of an adjustable column with no text in OpenXML

I would like to ask what units does column.width return when using Openxml? (IS it in EMU, metres, cm or dpi and how do i get its DPI equivalent?
From SpreadsheetOpenXmlFromScratch:
Note that the width of the digits depends on the font and the font size used. I'll be using the MeasureString() function of the Graphics class to measure pixel width.
Everything Vincent does is based on the font type and size. You will have to retrieve the font type and font size to run through the calculations.
EDIT: pp 40-50
No, it is using the font measurements, not the column text. Another excerpt:
Note that the width of the digits depends on the font and the font size used. I'll be using the MeasureString() function of the Graphics class to measure pixel width.
System.Drawing.Font drawfont = new System.Drawing.Font("Calibri", 11, FontStyle.Regular);
// I just need a Graphics object. Any reasonable bitmap size will do.
Graphics g = Graphics.FromImage(new Bitmap(256, 256));
Dim drawfont As New System.Drawing.Font("Calibri", 11, FontStyle.Regular)
' I just need a Graphics object. Any reasonable bitmap size will do.
Dim g As Graphics = Graphics.FromImage(New Bitmap(256, 256))
The font used should be the same as that used in your stylesheet. Otherwise you would be measuring for one font or font size, but using another font or font size to render your actual text in the Excel cell. I know it's obvious, but it's important to state here.
Specifically, it should be the font used in the Normal style. That word is capitalised for a reason. It refers to the cell style named Normal (together with "Good", "Bad" and "Neutral"). Get your friendly neighbourhood Excel geek to help you find the cell style option in Excel.
Some of his other methods do require text when he actually measures the width of a zero flanked by two underscores, then subtracts the width of the underscores to get a more accurate width, but this just requires the font name and style.
Now the MeasureString() function has a tiny problem. This is from the official documentation:
The MeasureString method is designed for use with individual strings and includes a small amount of extra space before and after the string to allow for overhanging glyphs.
What this means is that the following code will not exactly give you the pixel width of "0":
fWidthOfZero = (double)g.MeasureString("0", drawfont).Width;
fWidthOfZero = Convert.ToDouble(g.MeasureString("0", drawfont).Width)
Give it a try.

Change font size for whole document

I am trying to make a document but my font is currently to big.
Currenty i am changing the font like this
t2.Rows[0].Cells[0].Paragraphs.First().Append("Data").FontSize(9);
Is there a way to change the font size for the whole document ?

font size and font family comparison

i have extracted a PDF using Itextsharp and converted HTML using span tag. i want compare 2 font family font size. i had used http://www.codeproject.com/Articles/11454/A-word-wise-HTML-text-compare-and-merge-engine for text comparison . is there any method through which i an differentiate ,match two font family and font size . the final code i am getting like this in HTML .
this is HTML text of one PDF:"<"span style="font-family:ABCDEE+Calibri; ">
<"span style="font-family:ABCDEE+Calibri; "> steeds prominentere plaats in de organisatie in. Ik
<"span style="font-family:ABCDEE+Calibri; ">ben zeer <"/span">
this is HTML text of second PDF :<"span style="font-family:ABCDEE+Calibri;"> "<"/span>
<"span style="font-family:ABCDEE+Impact;"> steeds prominentere plaats in de organisatie in. Ik ben zeer <"/span>
here one PDF is having Calibri and second is Impact i want to find difference and highlight if its not matching. can you please tell me to compare font family and font size. thank you in advance

Categories