Welcome Guest Search | Active Topics | Sign In | Register

EO.PDF How to set padding the content when having an image logo header Options
Vasu
Posted: Wednesday, December 5, 2012 7:13:57 PM
Rank: Newbie
Groups: Member

Joined: 12/5/2012
Posts: 5
I have a header image logo which I am setting in render_BeforeRenderPage method
Here is my code. This code properly sets the logo image on every page. But my problem is that when the content is rendered, it is overlapping over the image. I can set th top padding for the first page.

But when the content is pushed to the second page, it is ovelapping with the header image. Can you please help how can I set the padding even for all the pages.

void render_BeforeRenderPage(object sender, AcmPageEventArgs e)
{
PdfPage page = e.Page;
System.Drawing.Image img = System.Drawing.Image.FromFile(@"filepath");
AcmImage image = new AcmImage(img);

AcmRender render = new AcmRender(
page, 0, new AcmPageLayout(new AcmPadding(0.3f,0.2f,0.1f,0f)));

AcmContent content = e.FirstPageContent;
while (content != null)
{
if (content.Tag != null)
{
render.Render(image);
break;
}
content = content.Parent;
}
}
eo_support
Posted: Wednesday, December 5, 2012 8:48:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

The AcmPageLayout object that you are already using in your code is used to set page margins. You will need to apply padding on the main render the same way. Also your logic seems to be wrong. I do not know why you have a loop inside render_BeforeRenderPage. That event is called ONCE for every page. So if you have the logo image appearing once on each page, then you should not have a loop. An easier way would be finish rendering the main content first, then do a loop like this:

Code: C#
foreach (PdfPage page in doc.Pages)
{
   ....render logo on each page....
}


Thanks!
Vasu
Posted: Thursday, December 6, 2012 10:55:44 AM
Rank: Newbie
Groups: Member

Joined: 12/5/2012
Posts: 5
Thanks for the response. I am still trying to evaluate the product and trying to understand the functionality. What I am still not able to understand is how to insert an image at the top on each page and also set the padding/margin for actual content to push down instead of rendering over the image. Here is my entire code and can you guide me what needs to be done to achieve right padding on each page.
PdfDocument doc = new PdfDocument();
AcmRender render = new AcmRender(doc);
AcmStyleSheet styleSheet = new AcmStyleSheet();

AcmContent root = new AcmContent(
new AcmParagraph(new AcmText("...Text which Spans multiple pages...")));
//I am setting the top margin and top padding to 1f. Does this effect to all pages?
root.Style.Margin.Top = 1f;
root.Style.Padding.Top = 1f;
render.Render(root);

System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\Temp\headerGraphic.png");
AcmImage image = new AcmImage(img);

foreach (PdfPage page in doc.Pages)
{
//How do I insert an image at the top on each page
}
doc.Save(outputFileName);
eo_support
Posted: Thursday, December 6, 2012 11:05:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You will need to do something like this in your loop:

Code: C#
foreach (PdfPage page in doc.Pages)
{
    System.Drawing.Image img = 
        System.Drawing.Image.FromFile(@"C:\Temp\headerGraphic.png");
    AcmImage image = new AcmImage(img);

    AcmRender render2 = new AcmRender(
        page, 0, new AcmPageLayout(new AcmAPadding()));

    render2.Render(image);
}


Thanks!
Vasu
Posted: Thursday, December 6, 2012 11:30:47 AM
Rank: Newbie
Groups: Member

Joined: 12/5/2012
Posts: 5
I tried that but giving me an error that the content is already rendered. Because My code already have one render before this probably
eo_support
Posted: Thursday, December 6, 2012 11:34:55 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

That's probably because you have the AcmImage outside of the loop. The code I give to you has the AcmImage inside the loop.

Thanks
Vasu
Posted: Thursday, December 6, 2012 11:49:28 AM
Rank: Newbie
Groups: Member

Joined: 12/5/2012
Posts: 5
Thats correct. It worked when I put the image inside the loop. But my main issue is that the text is still rendering behing the image. How can I push the text content to start rendering after the image displayed as a header logo from the 2nd page and on. Basically the text is overlapping with the image.

If that one works then I can actually start testing out other functions.
eo_support
Posted: Thursday, December 6, 2012 12:08:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

We have already told you that you need to adjust the AcmPageLayout object (in fact the AcmPadding object you pass to AcmPageLayout object) to adjust the padding of the output. You must try to understand the code you are writing in order to really get things working the way you wanted.

Thanks!
Vasu
Posted: Thursday, December 6, 2012 1:54:39 PM
Rank: Newbie
Groups: Member

Joined: 12/5/2012
Posts: 5
I understand that I need to get used to the different functions the product is providing. I tried diefferent setting on the ACMPadding object but without any luck on secondary pages. The padding provided by ACMPadding object is perfectly setting any type of margins on the first page.

But when the main content is extended beyond first page the padding do not work. Here is my entire code and I can also provide the image to try it out on your side. The image is 3 inches of width.

public override string RunDemo(string outputFileName, IDemoArgs args)
{
PdfDocument doc = new PdfDocument();
AcmRender render = new AcmRender(doc);
AcmStyleSheet styleSheet = new AcmStyleSheet();

AcmContent root = new AcmContent(
new AcmParagraph(new AcmText(@"...Text which Spans multiple pages...The land speed record for a crocodile is 17 km/h
(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.(11 mph) measured in a galloping Australian
freshwater crocodile. Maximum speed varies from
species to species. Certain types of crocodiles
can indeed gallop, including Cuban crocodiles, New
Guinea crocodiles, African dwarf crocodiles, and
even small Nile crocodiles. The fastest means by
which most species can move is a kind of ""belly
run"", where the body moves in a snake-like
fashion, limbs splayed out to either side paddling
away frantically while the tail whips to and fro.
Crocodiles can reach speeds of 10 or 11 km/h (
around 7 mph) when they ""belly run"", and often
faster if they're slipping down muddy riverbanks.
Another form of locomotion is the ""high walk""
where the body is raised clear off the ground.")).SetProperty("Style.Margin.Top", 0.5f));
//I am setting the top margin and top padding to 1f. Does this effect to all pages?
//root.Style.Margin.Top = 0.3f;
//root.Style.Padding.Top = 0.3f;
render.Render(root);


foreach (PdfPage page in doc.Pages)
{
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\Temp\headerGraphic.png");
AcmImage image = new AcmImage(img);
image.Style.Padding.Bottom = 1f;

AcmRender render2 = new AcmRender(
page, 0, new AcmPageLayout(new AcmPadding(0.5f,0.1f,0.5f,0.5f)));

render2.Render(image);
}

doc.Save(outputFileName);

return null;

}
eo_support
Posted: Thursday, December 6, 2012 7:28:53 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Of course setting your AcmText's padding has nothing to do with your page padding. You should pass the padding when you create an AcmRender object. See here for more details:

http://www.essentialobjects.com/doc/4/acm/advanced%20formatting/page_layout.aspx

Looking for "Setting Page Margins" in that page. The key is the AcmPageLayout object you passed to your render (this is the third time we mention AcmPageLayout to you, so please pay attention. :P). You had the code when you render your image. You just need to understand what each line and argument is for. The reference section should help you understand what each arguments mean.

If you still have any more questions, please let us know.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.