Inserting Image Objects

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
charlesd
Posts: 22
Joined: Thu Oct 20 2005
Location: Orem, Utah
Contact:

Inserting Image Objects

Post by charlesd » Thu Oct 20 2005

Two related questions:

I am searching for a way to insert quickly insert images into document. If an image is already loaded into memory can I create a picture based on an image handle, a stream, or some other in-memory device? Woul the format of this image be restricted to BMP and JPEG?

From the Developer Manual: "Developers can now define their own object types that are completely managed outside of the PDF Creator." I don't understand how this works. How do I define my own object type? How is this object type written to the resulting PDF file? Could I define an image object type that handles images that are CCITT compressed?

Thanks,

Charles

charlesd
Posts: 22
Joined: Thu Oct 20 2005
Location: Orem, Utah
Contact:

More questions...

Post by charlesd » Thu Oct 20 2005

If a document has a picture object is there any way I can access the image data? Can I get a handle to the data or save it out separately to another file, etc...?

Jose
Amyuni Team
Posts: 550
Joined: Tue Oct 01 2002
Contact:

Post by Jose » Mon Oct 24 2005

Hello,


I am not sure if this is what you are refering to but below is a visual basic 6.0 code snippet which illustrates the loading of a picture object in the PDF Creator from an image stream.


' Create picture object in the PDF Creator
Doc1.CreateObject acObjectTypePicture, "Picture1"

Set obj = Doc1.GetObjectByName("Picture1")

With obj

' set picture size

obj.Attribute("Left") = 100

obj.Attribute("Top") = 100

obj.Attribute("Right") = 900

obj.Attribute("Bottom") = 900



' set picture parameters

obj.Attribute("BitmapWidth") = img.Width

obj.Attribute("BitmapHeight") = img.Height

obj.Attribute("BitsPerComponent") = 24 ' assuming data is stored in RGB format



' get image pixels and store them in Creator Picture object

ReDim pixels(img.ARGBData.Count * 3)



For n = 0 To img.ARGBData.Count - 1

pixels(n * 3) = &H80 ' GetBlue(pixel)

pixels(n * 3 + 1) = &H80 ' GetGreen(pixel)

pixels(n * 3 + 2) = &H80 ' GetRed(pixel)

Next n



' Set bitmap data

obj.Attribute("BitmapData") = pixels



' Force image to grayscale as this will produce best results for scanned images

' obj.Attribute("GrayScale") = 1

End With


Hope this helps?

charlesd
Posts: 22
Joined: Thu Oct 20 2005
Location: Orem, Utah
Contact:

That helps quite a bit

Post by charlesd » Tue Oct 25 2005

Thanks for the reply. What other undocumented image attributes are available? or is this anywhere they are documented?

Charles

charlesd
Posts: 22
Joined: Thu Oct 20 2005
Location: Orem, Utah
Contact:

1 bit images

Post by charlesd » Tue Oct 25 2005

I've tested the above code and found that it works well, except for 1 bit images. At the end of my post is some sample Delphi code I've been using. It works fine for 24 bit images, but breaks on 1-bit images. I've found that by doubling the size of my pixels array the following code will "work" - it will display the image in an inverted form. However, if I try to save the resulting PDF I get an error.

Hope you can help?

Charles

Sample Delphi Code:

PDF.InitBlank;

ANumBytes:=(ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) div 8; // Calculate size (in bytes) of image data
if ((ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) mod 8) > 0 then
inc(ANumBytes); // round up for 1 or 4-bit images

SetLength(Pixels, ANumBytes); //Works (until you try to save) if SetLength(Pixels, ANumBytes * 2); is used when working with 1 bit images

ldImg.GetBitmapRow(Pixels, 0, ANumBytes); // Fills Pixels with image data

PDF.CreateObject(acObjectTypePicture , 'Pic10');
with PDF.GetObjectByName('Pic10') do
begin
Attribute['Left'] := 0;
Attribute['Top'] := 0;
Attribute['Right'] := PDF.PageWidth;
Attribute['Bottom'] := PDF.PageLength;
Attribute['BitmapWidth'] := ldImg.BitmapWidth;
Attribute['BitmapHeight'] := ldImg.BitmapHeight;
Attribute['BitsPerComponent'] := ldImg.BitmapBits; //24 for color, 1 for B&W, 8 for grayscale
Attribute['BitmapData'] := Pixels;
end;

PDF.Refresh;

Post Reply