VintaSoft Imaging .NET SDK and Plug-ins Discussions

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Add transparent image as background to PDF



Add transparent image as background to PDF

Post by David_karlsson »

Hi !
I'm evaluating Vintasoft.Imaging.Pdf. So far Vintasoft.Imaging.Pdf is very good. Unfortunately I do not find sample code to be able to add background image. I need Water Stamp/Watermark PDF . Therefore, I need to add a transparent image as a backround on pdf.


Re: Add transparent image as background to PDF

Post by Alex »

Hi David,

Thank you for your interest to our product.

For solving your task you need to create a PDF graphics for PDF page and specify that graphics must add new content before existing content:
https://www.vintasoft.com/docs/vsimagin ... ode).html

Here is an example that shows how to draw a watermark on the first page of PDF document:
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument pdfDocument = new Vintasoft.Imaging.Pdf.PdfDocument("document.pdf"))
{
    // create PDF graphics for first PDF page and specify that graphics must add new content before existing content
    using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics pdfGraphics = Vintasoft.Imaging.Pdf.Drawing.PdfGraphics.FromPage(
        pdfDocument.Pages[0],
        Vintasoft.Imaging.Pdf.Drawing.PdfGraphicsCreationMode.Prepend))
    {
        // create "watermark" image
        using (Vintasoft.Imaging.VintasoftImage image = new Vintasoft.Imaging.VintasoftImage("watermark.jpg"))
        {
            // draw "watermark" image on first PDF page
            pdfGraphics.DrawImage(image, new System.Drawing.RectangleF(0, 0, 600, 200));
        }
    }

    // save PDF document to a new file
    pdfDocument.Save("documentWithWatermark.pdf");
}

Please read how to draw graphics on PDF page here: https://www.vintasoft.com/docs/vsimagin ... _Page.html

Best regards, Alexander


Re: Add transparent image as background to PDF

Post by David_karlsson »

Thank you Alex.
I tested the code you posted but I do get an exception "{"Index was outside the bounds of the array."} System.IndexOutOfRangeException.

Is it possible to change opacity of the background image ?


Re: Add transparent image as background to PDF

Post by Alex »

I tested the code you posted but I do get an exception "{"Index was outside the bounds of the array."} System.IndexOutOfRangeException.

Is it possible to change opacity of the background image ?
Could you send us (to support@vintasoft.com) a small working project, which demonstrates the problem? We need to reproduce the problem on our side.

Best regards, Alexander


Page 1 from 1: 1