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 Oct 28, 2020 4:41 pm

Hello:

Does Spire.PDF for .NET include the ability to load a large PNG image (let's say it would be the background image), and then load smaller images that could be positioned over top that background image? I would expect to be able to define x,y coordinates for positioning each of the images, and then some way to define the layer of appearance (e.g. a "Send image A to the back, send Image B to the front, etc." capability). Any insight into this and/or sample code would be appreciated.

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Thu Oct 29, 2020 4:00 am

Hello,

Thanks for your inquiry.
Please refer to the following code. If this is not what you want, please provide some image files and your desired output to help us further investigate. Thanks in advance.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            //Create one page
            PdfPageBase page = pdf.Pages.Add();

            //Draw image A as the background image
            PdfImage img = PdfImage.FromFile(@"imageA.png");
            PdfTemplate template = new PdfTemplate(new SizeF(img.Width, img.Height));
            template.Graphics.DrawImage(img, new PointF(0,0));
            //Draw the template on page at specified location
            page.Canvas.DrawTemplate(template, new PointF(0,0), new SizeF(500,500));

            //Draw image B
            PdfImage image = PdfImage.FromFile(@"imageB.png");
            float width = image.Width;
            float height = image.Height;
            float x = (page.Canvas.ClientSize.Width - width) / 2;
            page.Canvas.DrawImage(image, x, 200, width, height);

            //Save the Pdf document
            string output = "output.pdf";
            pdf.SaveToFile(output, FileFormat.PDF);


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Wed Nov 11, 2020 1:34 am

Hello,

Greetings from E-iceblue.
How is your issue now? Could you please give us some feedback at your convenience?

Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Mar 16, 2021 8:18 pm

The layering seems to work and it saves a physical file.

Is there a way have it return a response stream instead of saving a file if a user were to click a "download" button from a .NET Core web application? Do I need to do some sort of byte conversion and then return a response?

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Wed Mar 17, 2021 9:50 am

Hello,

Thanks for your inquiry.
Please refer to the following code to achieve your needs. Feel free to contact us if you have further issues.
Code: Select all
        public IActionResult Download()
        {
            PdfDocument pdf = new PdfDocument();
            //....

            //save pdf to stream
            MemoryStream ms = new MemoryStream();
            pdf.SaveToStream(ms, FileFormat.PDF);         
            return File(ms.ToArray(), "application/pdf", "text.pdf");
        }


Sincerely
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Thu Apr 08, 2021 7:16 am

Hello,

Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?
Last edited by Andy.Zhou on Fri Apr 23, 2021 8:52 am, edited 1 time in total.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Wed Apr 14, 2021 9:38 pm

Andy.Zhou wrote:Hello,

Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?

Sincerely,
Andy
E-iceblue support team


Yes, that solved the issue, thanks!

mtceegee
 
Posts: 17
Joined: Wed Oct 28, 2020 4:32 pm

Thu Apr 15, 2021 1:47 am

mtceegee wrote:
Andy.Zhou wrote:Hello,

Greetings from E-iceblue!
Has the issue been solved now? Could you please give us some feedback at your convenience?

Sincerely,
Andy
E-iceblue support team


Yes, that solved the issue, thanks!


Glad to hear that the issue has been solved.
If you encounter any issues related to our product in the future, just feel free to contact us.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to Spire.PDF

cron