Add Header with image in word corrupts document - openxml

I have a Header with a table (1 row , 3 cells).In first cell there is a image and in 2nd and 3rd there are some text paragraphs
I append header to doc dynamically like this:
HeaderPart headerPart = mainPart.AddNewPart<HeaderPart>();
string rId = mainPart.GetIdOfPart(headerPart);
HeaderReference headerRef = new HeaderReference();
headerRef.Id = rId;
headerRef.Type = HeaderFooterValues.Default;
sectionProps.RemoveAllChildren<HeaderReference>();
sectionProps.Append(headerRef);
headerPart.Header = HeaderCreator.GenerateHeader();
headerPart.Header.Save();
In document there is a page with a group of shapes.
Everything works ok if I
Remove the page with shapes
Remove the logo from Header
Any suggestions?

Related

How to amend the below code to replace the "text" searched, in this case "london" for text in a particular cell, "Registration Form" Sheet Cell C15

Below is the code I am using to find text within a data table and return all rows that contain that text on another sheet. The code works on a full data table with now empty cells, however I want to perform the same task but instead of giving the text to search within the code, I want this to be determined by the user in a given cell on the sheet.
Sub CopyOverBudgetRecords()
Dim StatusCol As Range
Dim Status As Range
Dim PasteCell As Range
Set StatusCol = Sheets("Data Sheet").Range("c8:l35")
For Each Status In StatusCol
If Sheets("Registration Form").Range("c22") = "" Then
Set PasteCell = Sheets("Registration Form").Range("c22")
Else
End If
If Status = "london" Then Range(Status.End(xlToLeft), Status.End(xlToRight)).Copy PasteCell
Next Status
End Sub
I tried
using - If Status = "london" Then Range(Status.End(xlToLeft), Status.End(xlToRight)).Copy PasteCell
Replacing "london" With Sheets ("Registration Form").Range("c15").value
So - If Status = Sheets ("Registration Form").Range("c15").value Then Range(Status.End(xlToLeft), Status.End(xlToRight)).Copy PasteCell. This didn't work.

Footer image printed twice when printing certificates in iText

When we print certificate all most print in certificate but footer image is printing twice. I am using Pdfptable for printing footer image.
table = new PdfPTable(1);
int footerWidth[] = {100};
table.setWidths(footerWidth);
table.setWidthPercentage(100);
Image image2 = Image.getInstance("footerImage.jpg");
cell = new PdfPCell(image2,true);
cell.setBorder(0);
table.setTotalWidth(document.getPageSize().width()-document.leftMargin()-document.rightMargin());
table.addCell(cell);
//write the footer
table.writeSelectedRows(0, -1, document.leftMargin(), table.getTotalHeight()+document.bottomMargin(), writer.getDirectContent());
EventLog.write(appName,"done adding footer",logFile);
document.add(table);
Your table is added twice because you add it twice.
You add it a first time when you use writeSelectedRows():
table.writeSelectedRows(0, -1, document.leftMargin(), table.getTotalHeight()+document.bottomMargin(), writer.getDirectContent());
This adds the table at a very specific position defined by the coordinates:
x = document.leftMargin();
y = table.getTotalHeight()+document.bottomMargin();
You add the table a second time, when you do this:
document.add(table);
This adds the table at whichever position the page cursor is at, which is usually immediately after the previous content that was added with a document.add() method.
PS:
Headers and footers are usually added in an OnEndPage() page event. You're adding the footer only once. You may want to use page events to add the footer on every page.

Content alignment in ITEXT footer/header

hie ..
i have been using itext for the past couple of days and i am facing difficulty in aligning footer content .. if there are two or more lines in footer, is there a way to align each line differently .. i ve tried doing it in the following manner without any success ..
Paragraph footerInfo = new Paragraph("Date :-",FontFactory.getFont("Calibri",9,Font.BOLD));
footerInfo.add("\n");
footerInfo.add(new Paragraph("Place :- "",FontFactory.getFont("Calibri",9,Font.BOLD)));
Paragraph foot1 = new Paragraph("EmpID:-",FontFactory.getFont("Calibri",9,Font.BOLD));
foot1.setAlignment(Element.ALIGN_RIGHT);
footerInfo.add(foot1);
HeaderFooter footer = new HeaderFooter(footerInfo, false);
footer.setBorder(Rectangle.TOP);
document.setFooter(footer);

iTextSharp - Force text below image

My issue with images and iTextSharp is that I want to put a header in and the have the text below that point.
I can display the image and wrap the text but not get it to display below, even when adding New paragraph.
I am assuming there is some command around the aligmnent but I am struggling to find it even when looking at tutorials such as http://www.mikesdotnetting.com/Article/87/iTextSharp-Working-with-images
'Import Image
Dim vImagePath = "C:\sites\images\" & "Logo.jpg"
Dim jpg As Image = Image.GetInstance(vImagePath)
jpg.ScaleToFit(139.0F, 106.0F)
jpg.Alignment = Image.ALIGN_RIGHT Or Image.TEXTWRAP
jpg.IndentationLeft = 7.0F
jpg.SpacingAfter = 9.0F
jpg.BorderWidthTop = 6.0F
jpg.BorderColorTop = Color.WHITE
document.Add(jpg)
'##Main Document Header
Dim tableHeader As New PdfPTable(1) ' Number in brackets is number of columns
tableHeader.DefaultCell.Border = Rectangle.NO_BORDER
Dim phFirst As Phrase = New Phrase("Title", HeaderFont)
tableHeader.AddCell(phFirst)
document.Add(tableHeader)

Setting Alignment for each Element when more than one Element added to a PDFPcell

In a table, I have a few cells that contain multiple elements. For Example, to indicate address , the cell may contain a phrase containing an "ADDRESS:" header Chunk followed by another chunk containing the actual address:
FROM: -- Chunk 1 in Phrase
123 Main St, Some City, ST -- Chunk 2 in Phrase
As of now, to align the cell contents, I am using the following code in the PDFPcell:
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
However, this aligns all of the cell contents to the middle of the cell. If I want to put Chunk 1 at TOP_LEFT and Chunk 2 at BOTTOM_LEFT, is it possible to achieve it with iTextSharp? Essentially, I am looking for a way to align various elements within a cell at different locations.
Unfortunately the only way to do what you want is to add a sub-table in place of your multiple chunks.
t.AddCell("Row 1");
PdfPTable subTable = new PdfPTable(1);
subTable.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;
subTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
subTable.AddCell("Top Align");
subTable.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM;
subTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
subTable.AddCell("Bottom Align");
t.AddCell(subTable);
doc.Add(t);