I have a base document with sections created by programmatically inserting from a separate template document. The insertion is fine, but the footer isn't appearing on any extra pages created as a result of the insertion, i.e. the first page has a footer, but page two (created by inserting content) does not. If the original document has a two pages then it will render with a footer on the first two pages, but not the third.
Is there a way I can force the footer to render on all of the pages I have created?
There are three types of Headers/Footers in a Section e.g.
Header/Footer for First page,
Primary Header/Footer which can also be used for Odd numbered pages and
Header/Footer for Even numbered pages.
So, if you want to keep same Header/Footer across all pages in Word document, you can first clear all Headers/Footers (see Section.HeadersFooters.Clear() method) from all Sections in Document and then build/assign a single Primary Header/Footer to the first Section.
You might also want to turn off/on 'Different First Page' and 'Different Odd & Even Pages' options using 'Section.PageSetup.DifferentFirstPageHeaderFooter' and 'Section.PageSetup.OddAndEvenPagesHeaderFooter' properties.
Also, using Aspose.Words, you can programmatically control How Headers and Footers should appear during Joining and Appending Documents.
I work with Aspose as Developer Evangelist.
Related
I want to create a PDF document for double-sided printing to save paper on an report.
On odd pages after the end of an section, there should be a blank page reading "This page is intentionally left blank.", such that the report can be split by chapters as needed.
Any hints how to do this?
MigraDoc creates blank pages as needed. Just indicate in the PageSetup that you are creating a double-sided layout.
The tricky part is adding the text "This page is intentionally left blank". I think I'd add that text with PDFsharp after rendering the page with MigraDoc. But I'd rather leave the page blank, assuming the reader is smart enough to realize it was left blank to get a double-sided layout.
In MigraDoc, I know I can add a page count reference to the document using AddNumPagesField, but is it possible to determine if there are multiple pages?
The methods AddPageField and AddNumPagesField do not contain any useful information.
Basically, I want to do something like:
if(/* document has multiple pages*/) {
//do something here
}
With MigraDoc, pages do not exist until a document is rendered.
MigraDoc does not create any pages when rendering to an RTF file. Pages do not exist there.
MigraDoc creates pages when rendering to PDF.
AddPageField and AddNumPagesField are placeholders. They remain placeholders when rendering to RTF, they will be replaced by the real values when creating PDF - their values cannot be determined while the MigraDoc document is still being created.
What you can do: Assume the most likely case (e.g. multiple pages) and create the document. If it only has a single page, then discard it and create it again for the single-page case.
Or maybe use PDFsharp to modify the PDF file created by MigraDoc as needed, now adding the contents that depend on the page count.
I want a document with multiple pages. Every page should have the same header. One section of the document contains a long table, which stretches over multiple pages. On every page of this section I want to show a title above the table.
I came up with two solutions so far. Both seem hacky and have their downsides:
Make the title part of the header in this section. Feels wrong and is also annoying when I have other pages in the document which should contain the header but not the title.
Make the title part of the table and use HeadingFormat. Feels hacky as well because the title doesn't "fit" in the columns of the table.
Any better ideas?
Re 1: Put the table in a new section and set a new header for that section. One line can be the standard header shared by all pages, another line can be a special header for the table section.
Does not look hacky to me.
Re 2: You can set the HeadingFormat for several rows. So you can use the first row for the "header" without any border and with a MergeRight so it spans the whole page. Not really hacky and will look like normal text outside the table.
Solution 1 has a downside as every new section starts on a new page. Well, the table is so important that it even gets an own page header, so this downside should not matter.
A hacky and tricky solution would be using PDFsharp to add a special header on all pages with the table on it. I think I'd go for option 2.
I need to create and insert a QR code into existing word documents using .NET.
I've done the QR generation part. The 2 things I need to accomplish are:
Inserting the QR code in the footer of an existing word document (preferably using Open XML).
Each page of the word document has a unique QR code. This means that each footer would have to be different. (I could eliminate the footer and place the QR code as part of the body, but that word make flow of text complicated.)
Is it possible to accomplish this?
I haven't done this, but I believe that what you will need to do is
put each page in a separate Word section (and that means, in effect,
that you will need to decide what your page size and layout is)
create a footer containing one QR code to find out what XML Word
expects, and what type of image data you need to store in the .docx
(assuming that you are not attempting to store your image data
externally in spearate files).
create a footer for each section (and ensure that the footers are
not "linked to previous"), replicating the format you discovered in
point (2)
create a part for each QR code image, and a relationship to that
part
What I am even less sure about is whether Word will insist that you also store each image in another format (e.g. Windows Metafile or Extended metafile format). My guess is that Word will generate what it needs from your .jpg (or whatever). Or maybe you can use "AltChunks" in some useful way here.
The background to this is that if it were a .doc format document, you could have created a single footer containing a set of nested field codes that used the { PAGE } page number field to link to the correct image for each page - e.g.
{ INCLUDETEXT "c:\\myqrcodes\\qr{ PAGE }.jpg" }
or more likely, the slightly more complicated
{ PAGE \#"'{ INCLUDETEXT "c:\\myqrcodes\\qr{ PAGE }.jpg" }'" }
But if you try to save that as .docx format, even in compatibility mode, when you close and re-open, I think you wil just see one image on all pages. Further, even though that approach works with .doc format, it only works if the external image files are actually there and located at absolute addresses in the file system. If they are located at releative addresses (there is a way to do that) you or the end user will probably have to update the footer field codes to get the correct results.
Does anyone an idea how acrobat reader knows the page I am currently viewing?
For example - I have a PDF file which contains page numbers in footer in format - 1/A or 1/1 - divided into chapters, and acrobat knows that this is number of page - it doesnt write only total number of pages from beggining to this current page.
I am writing C# apps, WinForms, where I need to get number of page - in the same way as acrobat does.
I am converting each page into text with pdfLibView lib, but then, I need look at last page and use complex algorithms to find out which string in footer is page number - it can contain any other informations.
So any idea, how to get page number in format as it is written on this page?
It seems like your document uses page labels feature defined in PDF specification.
8.3.1 Page Labels says:
In addition, a document may optionally define page labels (PDF 1.3) to
identify each page visually on the screen or in print. Page labels and
page indices need not coincide: the indices are fixed, running
consecutively through the document starting from 0 for the first page,
but the labels can be specified in any way that is appropriate for the
particular document. For example, if the document begins with 12 pages
of front matter numbered in roman numerals and the remainder of the
document is numbered in arabic, the first page would have a page index
of 0 and a page label of i, the twelfth page would have index 11 and
label xii, and the thirteenth page would have index 12 and label 1.
You might try Docotic.Pdf library if you want to access page labels information in an existing document (disclaimer: I work for the vendor of the library).
Here is a sample for how to add Page Labels to PDF document. This sample doesn't show how to access existing labels but might give some clues for a start.