PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to include an Image when deployed via ClickOnce?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1919
Page 1 of 1

Author:  paulramsden [ Thu Feb 23, 2012 6:31 am ]
Post subject:  How to include an Image when deployed via ClickOnce?

I am deploying my app via ClickOnce and the document images are not being found at runtime. When debugging the images are displayed properly.

Do I need to calculate a different path?

Code:
        private void CreatePage(Protocol protocol, Document document)
        {
            // Each MigraDoc document needs at least one section.
            Section section = document.AddSection();

            // Put a logo in the header (Images is a folder in the project root)
            Image image = section.Headers.Primary.AddImage("Images/logo.gif");
            image.Height = "1cm";
            image.LockAspectRatio = true;
            ....
        }

Author:  paulramsden [ Thu Feb 23, 2012 8:28 am ]
Post subject:  Re: How to include an Image when deployed via ClickOnce?

Here is my work-around:

I put the image in a folder in the startup project. Set BuildAction to Content and CopyAlways. Pass the path 'Image\logo.gif' to my PDF builder class.

In the class

Code:
            // Put a logo in the header
            string file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LogoPath);
            //log.Debug("Load image " + file + ", Exists=" + System.IO.File.Exists(file));
            Image image = section.Headers.Primary.AddImage(file);
            image.Height = "1cm";



Perhaps there is a better way but this works.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/