Print Page | Close Window

Problem with a PDF file and DrawImage

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=2187
Printed Date: 29 Sep 24 at 1:15AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Problem with a PDF file and DrawImage
Posted By: tropenix
Subject: Problem with a PDF file and DrawImage
Date Posted: 13 Mar 12 at 6:42PM
I'm testing quickpdf activex with VB6 before to buy.
With same PDF files (generated from Crystal report export to pdf) the DrawImage function does not work correctly.
The image is inserted with very small dimensions, as well as with DrawText function
why?


ORIGINAL PDF
http://www.gibelsoftware.it/referto.pdf

MODIFIED PDF
http://www.gibelsoftware.it/referto.pdf - http://www.gibe lsoftware.it/refertoout.pdf


thanks






Replies:
Posted By: edvoigt
Date Posted: 13 Mar 12 at 8:24PM
Hi,

I see in your second PDF near to lower left corner a small image.

But without seeing your code snippet nobody may help you.

Inside the refertoout.pdf I see no trace of drawing with QuickPDF.


Cheers,

Werner


Posted By: tropenix
Date Posted: 14 Mar 12 at 9:56AM

The small image is the image insert by code, but does not respect the coordinates and dimensions

    FP = QP.LoadFromFile(FileNameout, "")
    QP.SetOrigin 1
    QP.DrawText 100, 10, "PROVA DI INSERIMENTO TESTO"
    QP.SaveToFile (FileNameout)
   
    QP.LoadFromFile FileNameout, ""
    IM = QP.AddImageFromFile(App.Path + "\logoiq.JPG", 0)
    lWidth = QP.imageWidth()
    lHeight = QP.ImageHeight()
    npag = QP.PageCount
    For i = 1 To npag
      QP.SelectPage i
      QP.SelectImage (IM)
      QP.SetOrigin 1
      QP.DrawImage 100 , 100 , lWidth , lHeight
    Next i
    QP.SaveToFile (FileNameout)

thank tropenix



Posted By: edvoigt
Date Posted: 14 Mar 12 at 10:28AM
Hi tropenix,

it is rather clear. You use QP.ImageWidth and QP.ImageHeight without thinking about the measurementunits. Both functions will give pixels. But inside your PDF you work with millimeters or points (default).

QP.DrawImage 100 , 100 , lWidth , lHeight

uses the pixelvalues (I guess 48x50 px) as point. A point is here defined as inch/72. An inch is 25.4 mm, so 48 points are 16.9 mm. If I see your refertoout.pdf in Adobe Reader, the image has big white borders, so it looks smaller, as it is. Not good for tests. And its posisition is not 100,100 from SetOrigin(1), which means topleft. It is so, because SetOrigin has to be used after Loadfromfile, origin is set for a document and not over boundaries for all of them.

What is to do? It depends only what you want. It's now your job, to calculate from pixelvalues to the wished scaling of images. Look to SetMeasurementUnits-function.

I wrote: Inside the refertoout.pdf I see no trace of drawing with QuickPDF.

I do not see too the text "PROVA DI INSERIMENTO TESTO" in . Because there SetOrigin is on right place, use a bigger y-value. The referencepoint is on baseline, not on top of text.


Cheers,

Werner


Posted By: tropenix
Date Posted: 14 Mar 12 at 11:07AM

Hi edvoigt,

My proble is:

I merge any pdf document, and i must add text adn images on merged file.

the code tested add correctly text and image on some pages but not in others
 


Posted By: edvoigt
Date Posted: 14 Mar 12 at 12:08PM
Hi,

I did a look inside of refertoout.pdf. There are the internals generated from Drawtext and Drawimage.

BT
1 0 0 1 100 831 Tm
(PROVA DI INSERIMENTO TESTO)Tj
ET
 q
121.92 0 0 127 254 460 cm
/QuickPDFIm79863349 Do
Q

The text should be drawn sharp on the upper border which is at 841 points. So his height has to be not more than 10 points. Ok. But it is other.

As I zoom with Adobe Reader to 1600% I see your text and image down in lower left corner. So I got another idea about the error-source. Its not in your code, but in the PDF, you want to modify. To proof this, take another input-PDF (made not with the program wich produces referto.pdf). And it explains that you have the problem by random.

I had such effects with same PDFs, whith incorect commands inside. To be more sure against this, set all normally defaults directly before doing your output. This is as first font and its size and measureunits.

You have rather the same situation as a subroutine would use unallowed global values and after its call all goes wrong. Here is the programmer of the PDF-source the bad gay.

 
Cheers
Werner
 


Posted By: edvoigt
Date Posted: 14 Mar 12 at 1:27PM
Hi,

here is a solution. Because the PDF has bad code inside, we try to correct it.

  QP.LoadFromFile('problematic.pdf','');
  QP.NormalizePage(0); // brings some "health" in the page
// the world is now ok again 
  QP.SetMeasurementUnits(0);                // unit mm
  QP.SetOrigin(1);
  QP.AddImageFromFile('blueFolder.bmp', 0);
  QP.DrawText(100, 10, 'This text should be at 100,10');
  QP.DrawImage(100,100, QP.ImageWidth, QP.ImageHeight);
  QP.SaveToFile('refer.pdf');

Normalizepage works with this pdf from you. But be careful.


Werner


Posted By: tropenix
Date Posted: 14 Mar 12 at 7:30PM
Hi,
thanks for your replay.
 
I had correct all pages of my pdf.
Now position text and image are correctly
 
very good
 
thanks Tropenix



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