iTextSharp - Header and Footer for all pages - pdf

I'm generating PDF by adding single PdfPTable which accommodates multiple pages.
Now I want to add header and footer to all these pages but it is only displaying on first page. Also margins are not working correctly.
I am overriding OnStartPage/OnEndPage events of class PdfPageEventHelper.
Kindly suggest best way to incorporate header and footers.
Thanks

Rule #1: don't use OnStartPage() to add a header or a footer. Use the OnEndPage() method only to add both the header and the footer.
Rule #2: don't add content to the Document object passed as a parameter to the event method. Use the DirectContent of the PdfWriter instead.
Rule #3: read the documentation and look at the examples and Q&As marked header and footer
You'll notice that your question is a duplicate of:
How to add HTML headers and footers to a page? (Java example)
How to generate a report with dynamic header in PDF using itextsharp? (C# example)
How to add text as a header or footer?
...
This answers your question: Kindly suggest best way to incorporate header and footers.
Your question about "margins not working correctly" is probably answered here: Why is my content overlapping with my footer? However, saying "margins are not working correctly" isn't an actual question. If I tell my doctor: "I don't feel well, please help me!" I can't expect him to help me if I don't give him more info. When I add headers and footers, the margins work correctly. If it doesn't work for you, you are doing it wrong...
The same is true for your allegation that the header and footer "is only displaying on first page." That's simply not true from our point of view. If you add the event to a PdfWriter like this:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
Header event = new Header();
writer.setPageEvent(event);
Then the OnEndPage() method is invoked every time a page is finalized.

Related

How to prevent MigraDoc header from repeating on additional new pages

Is there a way not to repeat a Migradoc header on every single page?
In my program I add an image to the header of my document as:
Section section = document.AddSection();
// Put a logo in the header
Image image = section.Headers.Primary.AddImage(#"C:\img\SmallLogo.png");
I would like the image to only appear on the first page of my document. However when the document spans multiple pages the image is added at the top of every single page.
How can I only add the image to the first page?
Header and Footer will be repeated on all pages of the section. It's a feature, not a bug.
To have the image only on the first page, you can use a "workaround" by setting a different header for the first page.
But IMHO the cleanest solution would be adding the image to the first page and not the header. This way it will only show once - on the first page where you want to have it.
BTW: Images are shapes and can be positioned anywhere on the page.

How Can I Format a Tumblr Title

Is there a way to format part of a Tumblr title? For example, I'd like to be able to italicize one word in a title. Anyway to do that?
Tumblr reads titles using the {Title} tag, so how it is rendered is determined all at once not word for word. This means that the style of your titles universally depends on the CSS used around them in the hard coding. If you use the traditional manner of titling your posts which is placing the title in the "Title" area, then no this is not possible. An alternative method is to not put a title in that area and instead just post all information into the body.
You would then use the "html" view to code the header as you wish to see it. Default tumblr layouts use h1 /h1 around their headers so this is generally what you would want to use. The reason you are going into html view is because there is no option currently on default tumblr to increase the font size outside of html view.
The very first coding in the html view should be similar to this:
<h1>Title with one word in <i>italics</i></h1>
Once done, turn off html view, press enter to get off of the title line and continue your post.

Setting template property from a content page (sitefinity 4.4)

the site that I'm working at is designed in a such way that CSS class is set for the tag on all the pages and the css classes used are different for all pages. Each page has common elements such as a header, a footer and a nav bar. I'd like to set up a single page template and include all common elements there but the body tag stands in the way. Is there a way to control a template from a content page? I know I can specify a code behind for content pages but i can't rely on content authors to enter it correctly each time they add a page. My current thinking is to set up multiple page template, one for each css class that is referenced in the body tag and put the common page elements into user controls. This is less than ideal because I will end up with lots of mostly identical templates and my user controls would not be editable easily. I guess I would have to use shared content items and such making the content authors hunt all over the site. I would have been much simpler to update the common header in a single page template.
Can someone please suggest a way?
I submitted a reply in the Sitefinity forums where you originally posted this, but just in case you check here first I'll ask the same question: how is the css class for body determined?
if it can be done programmatically you can use the code-behind of the Master Page for the template to set it so that it's handled automatically.
If this won't work, tell me more about how the css class is assigned and I will try to come up with an alternative.
hope this is helpful!

RDLC Print PageHeader Only on First Page

Is there a way to show the report header only on the first page? Just as expected the PageHeader.PrintOnFirstPage only shows or hides the header for the first page only. The customer wants the header to show up only on the first page, kinda like a title in a document. I looked at MS-RDL.pdf and RDL200501 with no luck. My reports are RDLC not RDL but it should not matter. If there is no straightforward solution I will look into writing custom code to supress the header on pages > 1.
If you need the header to be on the first page only, why struggle to put it inside the PageHeader anyway?
Instead, remove the PageHeader altogether and design whatever you want as the 'header' directly at the top most body.
Just my two cents.

Where I can get hyperlinks in pdf document structure (except "Annots" entry in page dictionary)?

I have two pdf documents (doc1 and doc2) with hyperlinks e.g www.somlink.com, www.somlink2.com.
According to PDF Specification I can get those hyperlinks via Link Annotations. Link Annotations can be found in pdf page's dictionary under "Annots" key.
CGPDFDictionaryRef pageDictionary = CGPDFPageGetDictionary(someCGPDFPage);
CGPDFArrayRef annots;
CGPDFDictionaryGetArray(pageDictionary, "Annots", &annots);
So the problem is that in one pdf document (doc1) I get that "Annots" array but in another document (doc2) there is no such entry in page dictionary.
And the thing is that with PDFKit.framework you can get those annotations in PDFPage class using - (NSArray *)annotations method even if there is no "Annots" entry in page dictionary.
I can't use PDFKit.framework on iPad/iPhone so I am working with Quartz framework :)
So it seems that there is another place where you can specify hyperlinks (or Link Annotations in PDF Reference), not only in "Annots" array and PDFKit.framework somehow know ho to do that.
Any ideas where can I get those hyperlinks?
Links on a page THAT YOU CAN CLICK ON have to be annotations. Period. No annotations, no links.
A string of text "http://blah.com" isn't necessarily a link, it's just a piece of text describing a URL. This may be what's causing your confusion.
It's also possible to embed link actions in bookmarks. I'm not at all familiar with PDFKit or Quartz, so you're on your own as far as API calls are concerned.
And finally, (having reread your question), I believe annotations can be inherited from their parent Pages object. Gonna have to look that one up... Nope. The annotations array MUST be in the leaf page object, or it's not valid.
Can you post links to your PDFs? Something Ain't Right here.
PDF viewer like Adobe Reader simply allows to click and navigate on a plain text, if it looks as a hyperlink - i.e. starts with http://, https://, ftp:// and ends up with some URL delimiter such as space. As simple as that ;)