We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add headers to existing pages?

Thread ID:

Created:

Updated:

Platform:

Replies:

123265 Mar 2,2016 08:46 AM UTC Mar 16,2016 12:11 PM UTC UWP 10
loading
Tags: Pdf
Mateusz Haex
Asked On March 2, 2016 08:46 AM UTC

I use PdfTextElement and PdfLayoutResult to create the content of my pages, however I'd like to add headers at the top of the pages, is there a way to catch an event and move the content of the page just a lit lower (and moving content that doesn't fit anymore to the next page) so a header could be added?

Mateusz Haex
Replied On March 2, 2016 10:29 AM UTC

I found the solution! :)

I simply add an event to the PdfTextElement (BeginPageLayout) and in the method that's called by the event I simply request the page's content to start at 0,30 (X,Y).

PdfTextElement element = PdfTextElement("Some text", someFont);
element.BeginPageLayout += new BeginPageLayoutEventHandler(BeginPageLayoutMethod);
PdfLayoutResult result = element.Draw(page, new RectangleF(x, y, width, page.GetClientSize().Height), layoutFormat);

private void BeginPageLayoutMethod(object sender, BeginPageLayoutEventArgs e)
{
  RectangleF bounds = e.bounds;
  if (!e.Page.Equals(_page))
  {
    bounds.Y = 30f;
  }
  e.Bounds = bounds;
}

Chinnu Muniyappan [Syncfusion]
Replied On March 3, 2016 06:39 AM UTC

Hi Mateusz,
We are glad to know that your issue has been resolved. Please let us know if you need further assistance.
Regards,
Chinnu

Mateusz Haex
Replied On March 11, 2016 12:34 PM UTC

I noticed that when text doesn't fit on the page anymore it goes to the next page as is expected, however the same does not apply to PdfImage. How can I fix this? How can I move the entire image (which is only 100x100px) to the next page?

Mateusz Haex
Replied On March 11, 2016 12:50 PM UTC

What I mean is there a similar object like PdfTextElement for images? Because with PdfTextElement I can use a PdfLayoutFormat and set that to PdfLayoutType.Paginate and PdfLayoutBreakType.FitPage. Is there a way to use a layoutformat for images as well?

Mateusz Haex
Replied On March 11, 2016 01:12 PM UTC

Nevermind, got it:

PdfImage image = new PdfBitmap(stream);
image.Draw(page, new RectangleF(x, y, 100, 100), layoutFormat);

Mateusz Haex
Replied On March 11, 2016 02:51 PM UTC

Turns out that the following line:

image.Draw(page, new RectangleF(x, y, 100, 100), layoutFormat);
Only draws a part of the image that will fit into the rectangle with a width and height of 100.
Can I somehow let the image scale so it fits within the rectangle?



Chinnu Muniyappan [Syncfusion]
Replied On March 14, 2016 11:56 AM UTC

Hi Mateusz,
We are suggesting to you to use Page.Graphics.DrawImage method to draw the image within the given bounds, use  Image.Draw to paginate the large image from one page to another page, we have created a simple sample for your reference, please refer the below code snippet and sample.
Code Snippet:
PdfBitmap img = new PdfBitmap(pngImage);

page.Graphics.DrawImage(img, new RectangleF(10, 10, 100, 100)); 

Sample link:
http://www.syncfusion.com/downloads/support/forum/123265/ze/Sample11972287588

Regards,
Chinnu

Mateusz Haex
Replied On March 15, 2016 08:29 AM UTC

That's what I used before, but "page.graphics.DrawImage" (1) does not support a layoutformat, so I replaced it with "PdfBitmap.Draw" (2) which does paginate the image, but I also need to scale it like the first one does. So I rather use the second one because that one paginates, but I also need the image to be smaller. Isn't there a way to do both?

Mateusz Haex
Replied On March 15, 2016 01:05 PM UTC

So I've done what you suggested and used page.Graphics.DrawImage instead and additionally wrote some code to create a new page and new y-location myself instead of the automatic pagination by image.Draw to compensate for the lack of that feature in page.Graphics.DrawImage.

Chinnu Muniyappan [Syncfusion]
Replied On March 16, 2016 12:11 PM UTC

Hi Mateusz,
We are glad to know that your issue has been resolved. Please let us know if you need further assistance.
Regards,
Chinnu

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;