Merging word documents and preserve their formatting, header and footer - c#

I have a trouble on merging multiple word documents into single. I had a scenario where I am generating word documents from html with header and footer. I have around 10-15 such documents. I am generating these word document individually and are working fine.
Now, I have a requirement to generate html of all 10 pages and combine them to single word report. These should preserve the individuals report's formatting, header and footer.
I have tried this in two ways but didn't get success:
Combined html of all pages into one html page and then finally saved file as word file.
Created word report for all 10 html files individually and merged them using Microsoft.Office.Interop.
I was able to merge the document but was not able to keep the header, footer and formatting of the individual document.
I have searched about section-break too but not sure how to use this.
Please see if anyone can guide me toward the possible solution or anything else that can help me.
Thanks in advance.
.

You could try merging with DocumentBuilder
If that doesn't give you enough control, see whether docx4j.NET (commercial edition) might help, with its demo merge webapp. Docx4j's MergeDocx provides fine grained control over header/footer behaviour.

Related

Headers lose styles after merging documents with Xceed Docx

Let me explain my scenario.
I am making use of Xceed Docx library to merge and manipulate word documents.
I have multiple templates that needs to be merged to form one customer facing document.
All of them having individual document headers, tables and images.
As per business requirements, we need to make use of content controls as there will be manual intervention.
PROBLEM:
All goes well and the merge works as expected, but it seems to drop the styling of the headers in merged document. But this only occurs when I include CONTENT CONTROLS (rich text content control)!
For example: Header 1, Header 2 becomes normal text....
Has anyone experienced anything similar with this library?
Is there something I am doing wrong or missing?
I did try and contact the developers of DocX, with no avail.
I tried merging the files with OpenXml using AltChunk.
This did work but not to the extend that I required.
Let me explain.
AltChunk inserts the entire file (doc2.docx) into the base file(doc1.docx)
and then only add reference of doc2 inside doc1's XML file.
Hope that makes sense.
MS Word can open this file, but when I want to make changes using DocX it is unable to load the file.
I ended up using Docx for all the document manipulation and OpenXmlPowerTools to merge the documents.
OpenXmlPowerTools seems to resolve the above mentioned issue as its does seem to do a complete image, chart and text merge.
I hope this helps someone in the near future ;-P

Making PDF file from C# application

How do I make a PDF with C# application?
I would like to make an application which creates a PDF document, but it could be Excel too.
I wish to make a file which contains tables and header.
You could use ITextSharp to create your PDF file.
And this post to help you with Excel.
Take a look at PDFFlow library for generation of PDF in C#. It has features that you need: tables, multi-page spread tables, repeating areas (headers, footers, left, right), table repeating headers... and even more unique features (like automatic page creation, multi-level list, word-like tabulation, barcodes/QR codes, etc...) and easy fluent syntax:
var DocumentBuilder.New()
.AddSection()
.AddParagraph("Hello World!").SetFontColor(Color.Red)
.ToSection()
.AddImageToSection("Smile.png")
.AddTable()
.AddColumnToTable("Column1").AddColumnToTable("Column2")
.AddRow().AddCellToRow("Row1, Cell1").AddCell("Row1, Cell 2")
.ToTable()
.AddRow().AddCellToRow("Row2, Cell1").AddCell("Row2, Cell 2")
.ToDocument()
.Build("Result.pdf");
This is first pages of my business document with multi-page spread table and repeating headers, which I created using this library:
There are examples with source code and explanation, I found them very useful: examples.
Hope, this will help.

PDFsharp trim page white-space, merge pages

I am merging some PDF documents using PDFsharp, and I want to do the following:
-> the LAST page of FIRST document contains just 2-3 lines of text, so I would like the FIRST page of SECOND document to begin immediately after those 2-3 lines...
Now it goes to the new page, so there is lot of Space-wasting.
Thanks.
PDFsharp does not render PDF pages, PDFsharp does not parse PDF pages.
When using PDFsharp there is no easy way to achieve what you want and you will have to add a lot of code to get it done.
It might be easier with another library, but I cannot give you any names.

Navigate By Columns using Aspose.words in C#

Am evaluating the Aspose.words for one of my client, almost all of the feature i have migrated from MS Word library to Aspose.word library. Just one more to go, but am struggling to find the solution for the below:
We have Template document which is in .docx format. Template has a Two column page layout. at run time system would copy paste the content from other document to this Template document. still this steps works fine.
When i open the template page it looks good with 2 column layout.
But we have some logic that should read the last line of First Column & checks whether the text is in specific format, if it is then moves one line down which would automaticaly moves to the next column.
This logic is easily acheivable in Word but i couldn't find any refference in Aspose.words to implement this.
Also i tried to find different option by convering the document to Xml. & found that there is one node called . but this node is visble only when i save the document as xml From Microsoft word. Not occurs if i save the document as xml from Aspose.words.
Please advice me to solve this issue.
Thanks in advance
Gunasekara S
we just have finished integrating a feature into Aspose.Words to open up access to the rendering engine so that each element of the rendered document can be read as it appears as pages, columns, lines, spans etc. This functionality is exactly what you need and will be available in the next version of Aspose.Words which is expected to release in about a week's time. Soon I will be sharing the code snippet to accomplish your requirement.
My name is Nayyer and I am developer evangelist at Aspose.

Justify text in a Report

In my work we need to generate contract documents that dynamically extract information from the database to personalize client related information.
These documents not only have text, but also they need tables with dynamic rows (ie.: shows some products owned by the client). These tables can be placed in different parts of the document and they can be between paragraphs.
The important thing is that: the texts must be justified (a legal requeriment of my country)
We do these documents with Reporting Services and export them to PDF, but this tool doesn't provide justified text.
i did some googleing and found that there is no way to justify text in Reporting Services.
Is there another way to do this? if not, can you give me some alternative to solve this issue?
We work with ASP.NET in C#.
Thanks in advance
You might be able to export them to Word, where I believe you would have greater control over the justification, then convert the Word document to a PDF.

Categories

Resources