graphics.DrawString is not writing text on multiple page PDF

Hi we are using syncfusion PDF viewer, we are drawing  string on top of pdf. Code is 

 public PdfLoadedDocument StampPDF(byte[] byteArray, string stampingName)
        {
            PdfLoadedDocument doc = new PdfLoadedDocument(byteArray);
            //Get first page from document
            PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
            //Create PDF graphics for the page
            PdfGraphics graphics = page.Graphics;
            //Set the standard font.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold);
            //Draw the text.
            graphics.DrawString(stampingName, font, PdfBrushes.Black, new PointF(0, 0));
            //Save the document.

            return doc;
        }

writing text on first page, can you please tell me what we need to do so it will write and show same text in all pages if pdf have multiple pages.

Thanks


2 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team July 12, 2018 07:24 AM UTC

Hi Farhan, 
 
Thank you for contacting Syncfusion support. 
 
Yes, it is possible to stamp a PDF document using Essential PDF. Please find the code example which illustrates adding page stamp in every page of the PDF document. 
//Loads a existing PDF document 
PdfLoadedDocument document = new PdfLoadedDocument(byteArray); 
//Initailizes PdfFont for stamp text 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f, PdfFontStyle.Bold); 
//Iterating each page and applying stamp text 
foreach (PdfPageBase lPage in document.Pages) 
{ 
    PdfGraphics graphics = lPage.Graphics; 
    PdfGraphicsState state = graphics.Save(); 
    graphics.SetTransparency(0.25f); 
    graphics.RotateTransform(-40); 
    graphics.DrawString("imported content using essential pdf", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); 
} 
//Saves Stamped PDF document 
document.Save(); 
document.Close(true); 
 
You can also refer our online sample for stamping an existing PDF document which is available here. 
 
Please let us know if you have any questions. 
 
Regards, 
Dilli babu. 



FS Farhan Syed July 13, 2018 09:06 PM UTC

Thanks this is working.

Loader.
Up arrow icon