Print Page | Close Window

Background image in existing PDF

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1947
Printed Date: 15 May 25 at 11:12AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Background image in existing PDF
Posted By: nexent
Subject: Background image in existing PDF
Date Posted: 07 Sep 11 at 3:15PM
Hi there,

I'm using QuickPDFLite0725.PDFLibrary in VB6.
I need to add a background image (fitting all page) in every page of an existing PDF created by Crystal Reports 9.

I've tried the following code:

   QP.LoadFromFile SourceFile

   Dim lngImage As Long
   lngImage = QP.AddImageFromFile(ImageFile, 0)
  
   Dim I As Integer
   For I = 1 To QP.PageCount() '- 1
      QP.SelectPage I
      QP.SelectImage lngImage
      QP.SetOrigin 1

      QP.DrawImage 0, 0, QP.PageWidth(), QP.PageHeight()
   Next

   QP.SaveToFile TargetFile

The first problem is that the image is drawn over the existing content, and not behind.
The second (maybe a bug?) is that the image is drawn mirrored.
Any ideas?

I could buy the full version, if that would solve the problem.
Thanks.





Replies:
Posted By: AndrewC
Date Posted: 07 Sep 11 at 3:21PM

There is a function on the full version that fixes the Mirroring problem.

  QP.NormalizePage(page);

To draw the background underneath you would need to use the CapturePage and DrawCapturedPage functions which are not available in the Lite version.

There is a 30 day trial available as well which will make it easier to decide.

Andrew.


Posted By: nexent
Date Posted: 07 Sep 11 at 3:29PM
Hi Andrew,

thanks for your quick reply.
Can you give me some sample code for the CapturePage and DrawCapturedPage functions?
I could test using the trial, I need to solve the problem asap.

Thanks again





Posted By: AndrewC
Date Posted: 07 Sep 11 at 4:12PM
This code should do everything you need.  You just need to put your image drawing code in where I have indicated.  This will work on multiple page PDF's and also for a single page PDF.

Basically when you capture a page, that page is deleted and the contents are captured.  So we add a new page to the end of the document and draw the captured page onto that new page.  We then repeat the process for each page.

            double pageWidth, pageHeight;
            int capturedPageId;

            int ret = QP.LoadFromFile("Pages.pdf", "");
            QP.SetOrigin(1);

            int numPages = QP.PageCount();
            int pageId;

            for (int i = 1; i <= numPages; i++)
            {
                QP.SelectPage(1);                       // Always select page 1 as the pages get deleted.
                QP.NormalizePage(0);                    // Fix the page mirroring.

                pageWidth = QP.PageWidth();
                pageHeight = QP.PageHeight();
                
                capturedPageId = QP.CapturePage(1);     // This deletes the page from the document.

                pageId = QP.NewPage();
                QP.SetPageDimensions(pageWidth, pageHeight);

                // TODO -----------------------------------
                // Draw your stamp or background image here
                // TODO -----------------------------------

                // Now draw the original page on top.
                ret = QP.DrawCapturedPage(capturedPageId, 0, 0, QP.PageWidth(), QP.PageHeight());
            }

            QP.SaveToFile("newpages.pdf");



Posted By: nexent
Date Posted: 07 Sep 11 at 5:53PM
There's a problem... :(
my collegue already installed trial version 7.26 on development pc, and that version has expired a few days ago.

Now, I have installed version 8.11, but I've got a message stating that the trial license key "could not be validated" (obviously... ;)

Can I have a new key for the 8.11 version?
Thanks






Posted By: nexent
Date Posted: 08 Sep 11 at 9:32AM
Never mind, problem solved.
Thanks



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk