Search code examples
leadtools-sdk

LEADTOOLS : How to add image into PDF file in a specified location


I am trying with RasterImage option to load PDF file and Save method to combine image. But i am getting invalid PDF file.

Also, want to place the image in bottom corner of PDF file.

Any code snippet would be great help.

Thanks


Solution

  • This is LEADTOOLS support. Since you mentioned "RasterImage", I'll assume you're using our .NET classes.

    If your requirement is to combine an image at the lower corner of the PDF page then save it as a raster (bitmap) PDF, one way of doing that is using code similar to this:

    RasterImage pdfPage = _codecs.Load("Source.pdf");
    RasterImage smallerImage = _codecs.Load("SmallImage.png");
    LeadPoint combinePoint = new LeadPoint(pdfPage.Width - smallerImage.Width, pdfPage.Height - smallerImage.Height);
    LeadRect destRect = new LeadRect(combinePoint, LeadSize.Create(smallerImage.Width, smallerImage.Height));
    CombineCommand combine = new CombineCommand(smallerImage, destRect, LeadPoint.Create(0, 0), CombineCommandFlags.Destination0 | CombineCommandFlags.OperationAdd);
    combine.Run(pdfPage);
    _codecs.Save(pdfPage, "target.pdf", RasterImageFormat.RasPdfLzw, 24);
    

    Please note that we don't always monitor StackOverflow for LEAD-related questions, so if you have a technical question about our toolkit, you might want to use our free email, chat or forums support services.