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 Jan 13, 2021 12:31 pm

Im Tring to add img to pdf and the img is run over the text

how can i add img in the top off the pdf with out run over the text?

felix13579
 
Posts: 2
Joined: Mon Oct 19, 2020 8:20 am

Thu Jan 14, 2021 1:45 am

Hello,

Thanks for your inquiry!

Please refer to the following code to add the image in the top of the pdf without running over the text.
Code: Select all
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"E:\testdoc\sample.pdf");

            foreach (PdfPageBase page in pdf.Pages)
            {

                PdfImage image = PdfImage.FromFile(@"E:\downapp\pic\color.jpg");
                //set image x coordinates
                float x = 0;
                //set image width
                float width = image.Width;
                //set image height
                float height = image.Height;
                //set image y coordinates
                float y = page.FindAllText().Finds[0].Bounds.Y - height - 2;
                //draw image
                page.Canvas.DrawImage(image, x, y, width, height);
            }

            pdf.SaveToFile("AddImgTop.pdf", FileFormat.PDF);
            pdf.Close();


If this does not meet your needs, please provide us with your input file and output sample for further investigation. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Jan 22, 2021 7:31 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF

cron