Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Aug 09, 2017 7:02 am

Hi,

I would like to report / ask for feedback on handling ReplaceImage() when PDF Template is used.
So what is the problem:
When I'm invoking following code on regular PDF created with SpirePDF it works ok
Code: Select all
...
var image = PdfImage.FromStream(replacement);
page.ReplaceImage(0, image);


But when I add header / footer to given PDF using this code

Code: Select all
              headerSize = 40;
              var topSpace = new PdfPageTemplateElement(_doc.PageSettings.Size.Width, headerSize.Height)
              {
                  Foreground = true
              };
              _doc.Template.Top = topSpace;
              topSpace.Graphics.DrawString(header, font, PdfBrushes.Black, originalMargins.Left, 0);
           
            foreach (PdfPageBase origianlPage in original.Pages)
            {
                var page = _doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height));
                origianlPage.CreateTemplate().Draw(page, 0, -(headerSize));
            }

then ReplaceImage code from above clears entire PDF (it leaves only header all content is removed).

This is for sure something with this line
Code: Select all
origianlPage.CreateTemplate().Draw(page, 0, -(headerSize));

but i cannot figure out what exactly is going on.

Any ideas / help?

Bartosz

raku
 
Posts: 3
Joined: Tue Jul 25, 2017 6:40 am

Wed Aug 09, 2017 10:52 am

Hello,

I got the news from our dev team that the page.ReplaceImage() method can only be available for the images for the body part. If the image is in the header, mistake might occur like yours.
So sorry for the inconvenience caused.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Aug 10, 2017 11:12 am

Hi again,

Maybe I described it differently but the image is in "body" not in the header of footer.
In my my example that I've posted see that header contains only text.
Code: Select all
topSpace.Graphics.DrawString


The image is in the body of the source pdf (before template function was used). So to speak image is placed inside "origianlPage" in previous example:
Code: Select all
origianlPage.CreateTemplate().Draw(page, 0, -(headerSize));


And only after applying CreateTemplate().Draw... the PDF that is created cannot be manipulated using ReplaceImage()

raku
 
Posts: 3
Joined: Tue Jul 25, 2017 6:40 am

Fri Aug 11, 2017 5:42 am

Hello,

Sorry for my misunderstanding.
I have reproduced the issue and referred it to our dev team. Once there's any progress or update, I'll let you know.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Aug 11, 2017 7:44 am

Hi,

Thanks for information. I'll wait for update / fix on this.

Bartosz

raku
 
Posts: 3
Joined: Tue Jul 25, 2017 6:40 am

Fri Aug 11, 2017 8:06 am

Hi,

Thanks for your quick response.
I will inform you once the hotfix is available.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Sep 26, 2017 3:25 am

Hi,

Glad to inform that the hotfix is available now, please download the Spire.PDF Pack(Hot Fix) Version:3.9.360 to have a check.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Sep 27, 2017 7:28 am

Hello Bartosz,

Have you tried the hotfix?
Could you please give us some feedback?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.PDF