Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an image to whole page with iText 7 C#

Tags:

c#

image

itext

I have a .png files which are size of A4. I am adding them to the .pdf. It is working but my image is not covering all .pdf document page and it is leaving the white edges around it. How to cover whole page with my image?

    String dest = "C:\\ImagePaged.pdf";
    PdfWriter writer = new PdfWriter(dest);
                      
                        // Creating a PdfDocument  
    PdfDocument pdfDoc = new PdfDocument(writer);
                      
                        // Creating a Document 
     iText.Layout.Document document2 = new iText.Layout.Document(pdfDoc);
                        
                    
                            // process and save pages one by one
                            for (int i = 0; i < 10; i++) //count of .png images
                            {
      
    
 iText.IO.Image.ImageData imageData =  iText.IO.Image.ImageDataFactory.Create($"C:\\ImagePage{i}.png");
    
                                    Image image = new Image(imageData);
                                  
 
                                    document2.Add(image);
                       
                                }

 document2.Close();

I guess I need somehow to set page edge parameters. But how to do that.

How it looks from pdf

like image 332
V. Z Avatar asked Sep 03 '25 16:09

V. Z


1 Answers

Pretty sure it is this one

pdfDoc.SetMargins(0, 0, 0, 0);
like image 189
Thomas Koelle Avatar answered Sep 05 '25 05:09

Thomas Koelle