Print Page | Close Window

Same Image Drawn on PDF at Different Sizes

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


Topic: Same Image Drawn on PDF at Different Sizes
Posted By: pshay543
Subject: Same Image Drawn on PDF at Different Sizes
Date Posted: 10 Oct 11 at 6:25PM
I'm having experiencing a strange behavior and it may just be how I am coding it or my lack of understanding of the component / PDF. 
 
I have a 64 x 64 pixel image that I add to a PDF and then Draw it 3 times on the same page. The first time it is drawn it is drawn large and the second and third time it is drawn with the correct size.   Below is my code: 
 
PDFLibrary.SetPageSize('Letter');
PDFLibrary.SetMeasurementUnits(0);     // Set to Millimeters
 
// Select the 64x64 Image
PDFLibrary.CompressImages(1);
pdfLibrary.SelectImage(iImageID);

PDFLibrary.SetOrigin(1);

PixelsPerMM(MyIMGScrollBox.Graphic.Canvas,xMili,yMili);   // get Pixels per Millimeter

iWidthDPI := PDFLibrary.PageWIdth;
iHeightDPI := PDFLibrary.PageHeight;
 
// Draw the Image at 0,0 and it is Larger than the next two images
PDFLibrary.DrawImage(0,0,(MyIMGScrollBox.Graphic.Width / xMilli),(MyScrollBox.Graphic.Height / yMilli));
 
// Still the same image selected and these are drawn with the proper size.
PDFLibrary.DrawImage(200,200,(MyIMGScrollBox.Graphic.Width / xMilli),(MyScrollBox.Graphic.Height / yMilli));
PDFLibrary.DrawImage(400,400,(MyIMGScrollBox.Graphic.Width / xMilli),(MyScrollBox.Graphic.Height / yMilli));
 
Is there something special about drawing at 0,0 ? or is this a bug when an image is drawn at that location?   The Image is a BMP.  
 
Any Help would be appreciated.  
 
Thank you,
Paul
 



Replies:
Posted By: pshay543
Date Posted: 10 Oct 11 at 6:39PM
I think I figured out the issue (Sort of).    As soon as I use the AddImageFromStream it draws the image on the current PDF page even prior to calling the draw command from the quickpdf library. This is over lapping the actual image drawing at 0,0. 
 
According to the reference guide: The addImageFromStream adds the Image to the document and then it can be drawn anywhere.  However, the addImageFromStream is adding it directly to the page I'm working with. 
 
How can I prevent this from adding to the page?   See my full Code below:
 
            MyScrollBox.Clear;
            MyScrollBox.LoadFromFile(sImageFiles[iImageFileCount], i);
            MyScrollBox.SaveToStream(ms, 'BMP');
            ms.Position := 0;
 
            if bFirstTime then
              bFirstTime := False
            else
                iImageCOunter := pdflibrary.NewPage;

            pdflibrary.SelectPage(iImageCounter);
 
// This command is drawing the image on the current page.
            iImageID := pdflibrary.AddImageFromStream(MS, 0);
 
 
            iWidth := PDFLibrary.ImageWidth;
            IHeight:= PDFLibrary.ImageHeight;
                          // Set the paper size
            PDFLibrary.SetPageSize('Letter');
            PDFLibrary.SetMeasurementUnits(0);     // Set to Millimeters

            PDFLibrary.CompressImages(1);
            pdfLibrary.SelectImage(iImageID);

            PDFLibrary.SetOrigin(1);

            PixelsPerMM(MyScrollBox.Graphic.Canvas,xMili,yMili);

            dScale := Math.Max(xMili / PDFLibrary.PageWidth, yMili / PDFLibrary.PageHeight);

 //           PDFLibrary.DrawImage(100,100,(MyScrollBox.Graphic.Width / xMili),(MyScrollBox.Graphic.Height / yMili));
 //           PDFLibrary.DrawImage(200,200,(MyScrollBox.Graphic.Width / xMili),(MyScrollBox.Graphic.Height / yMili));
 //           PDFLibrary.DrawImage(400,400,(MyScrollBox.Graphic.Width / xMili),(MyScrollBox.Graphic.Height / yMili));
 
 
Notice how I have the draw image commands commented out but yet the PDF shows the image in the upper left corner when saved.
 
That is why In my previous post of drawing at 0,0 I thought that the image was larger.  It wasn't the image from the drawimage but the image placed on the page from the addImageFromStream.
 
Any suggestions?
 
Thank you,
Paul
 
 


Posted By: tfrost
Date Posted: 11 Oct 11 at 12:47PM
I use AddImageFromStream and do not see this problem (in 7.24).  However in checking my code, I see that I use a second parameter of 3, not 0.  This seems to have happened because at one time the stream contained a PNG file, and when it was changed to use a BMP instead, I forgot to change the parameter.  We changed the image format because using a PNG resulted in a huge PDF file.  Worth a shot, maybe (but still an issue needing to be resolved)?


Posted By: pshay543
Date Posted: 11 Oct 11 at 12:58PM
Thanks,   I tried placing a 3 as the parameter for the AddImageFromStream but I get the same result.  This is version 7.26.  
 
Thank you,
Paul
 


Posted By: pshay543
Date Posted: 11 Oct 11 at 6:48PM
The same code as above produces the same results in 8.11.   Either my understanding of how the assignImagefromStream works and my coding is wrong or a bug must have been introduced sometime after 7.24.
 
Thanks,
Paul
 


Posted By: tfrost
Date Posted: 12 Oct 11 at 12:12AM
I should have written 7.26 in my earlier message.  I have not had the problem you describe with any of 7.24 to 8.11.


Posted By: pshay543
Date Posted: 12 Oct 11 at 1:11AM
I'm really confused now :). 
 
I have tried with Delphi Version 6 and Version 7.    I just rebuilt my machine and will have to load Delphi 2005 up to see if it is possibly delphi version related.
 
Do you mind me asking you what version of Delphi you are using?
 
Thank you,
Paul
 


Posted By: tfrost
Date Posted: 12 Oct 11 at 11:00AM
I use DXE (and formerly D2010) for QuickPDF v7 and tested with DXE2 and QuickPDF v8.  My suggestion would be to open a support case as I don't see how the Delphi version could affect this.


Posted By: AndrewC
Date Posted: 13 Oct 11 at 2:34PM
I have reviewed the QPL source code and there is no way that AddImageFromFile also draws the image onto the PDF.  The AddImageFromFile and DrawImage commands are totally separate.

Andrew.



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