Print Page | Close Window

Image to 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=337
Printed Date: 08 May 24 at 4:05AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Image to PDF
Posted By: skwirelboy
Subject: Image to PDF
Date Posted: 27 Feb 06 at 1:13PM

I want to add convert a tiff to a pdf (ok I guess I'm not converting but just embedding).

I'm using Delphi and here's what I have so far:

  QP := TiSEDQuickPDF.Create;
  QP.UnlockKey('[MyKey]');
  QP.NewDocument;
  QP.AddImageFromFile(dlg1.filename, 1);
  QP.SelectPage(0);
  QP.AddImageFromStream(stream, 0);
  QP.DrawScaledImage(1, 1, 100);

qp.SaveToFile('c:\pdf.pdf');

This is as far as I've got. I have a saved file which is roughly the size of the image I'm inserting, but when you open it it is blank. I've tried setting selectPage to 1 as well as 0, but to no avail.

If anyone can give me any pointers I'd be much obliged.

 

Thanks,

 

Mark

 

 




Replies:
Posted By: chicks
Date Posted: 27 Feb 06 at 1:51PM
RTFM

AddImageFromFile() returns an image ID, you then need to use SelectImage() with that ID, finally DrawScaledImage()

Also, the second argument to AddImageFromFile() is normally 0, unless dealing with multi-page TIFFs.

Your example also shows reading image data from a non-initialized stream.


Posted By: skwirelboy
Date Posted: 28 Feb 06 at 4:28AM

Thanks for reply. I'm actually loading from stream, but thought it easier from my example if I showed it as being loaded from file. I've tried selectimage, but still don't seem to be getting anywhere (ie blank pdf, yet roughly same size as the tiff file). My code now is:

QP := TiSEDQuickPDF.Create;
  QP.UnlockKey('[MyKey]');
  QP.NewDocument;
  QP.SelectPage(0);

  Stream.Position:=0;

  QP.SelectImage(QP.AddImageFromStream(stream, 0));
  QP.DrawScaledImage(1, 1, 100);

  QP.SaveToFile('c:\pdf.pdf');

The stream is initialised although the example doesn't show the code and the stream contains a valid tif (tested at end of process by saving to a file). I'm not sure to what SelectPage should be set (ie whether 0 based index), but I;ve tried both as 0 and 1 and same result.

Any ideas why the above doesn't work?

Thanks in advance.

Mark



Posted By: chicks
Date Posted: 28 Feb 06 at 11:12AM
Try checking ALL return codes from QP functions, might be something as simple as a mis-typed key, etc.

Also, QP has problems with some images, though it's mostly a rendering issue, not embedding, in my experience.

Added:

Just noticed that you're positioning the image at top,left=1,1. Note that the origin is the bottom left corner unless you specify otherwise, so your image is probably being embedded, but its top is just at the bottom of the screen. See the SetOrigin() function.



Posted By: skwirelboy
Date Posted: 28 Feb 06 at 2:08PM

Thanks again. I've added setOrigin.

Drawing a scaled image was also failing for me, although I have no idea why. I've changed to DrawImage, but I'm setting the dimensions of the page first so that they match the image dimensions and this seems to do the trick perfectly.

Many thanks for your help. Don't think I would have got there without it.

Cheers,

Mark




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