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.
Add transparent image as background to PDF
Moderator: Alex
-
- Posts: 8
- Joined: Mon Jan 14, 2019 12:55 pm
Re: Add transparent image as background to PDF
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:
Please read how to draw graphics on PDF page here: https://www.vintasoft.com/docs/vsimagin ... _Page.html
Best regards, Alexander
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:
Code: Select all
// 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
-
- Posts: 8
- Joined: Mon Jan 14, 2019 12:55 pm
Re: Add transparent image as background to PDF
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 ?
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
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.David_karlsson wrote: ↑Mon Jan 14, 2019 3:18 pm 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 ?
Best regards, Alexander