Blog: Tech Talk

agsdix-fas fa-home

Blog: Home

agsdix-fas fa-pen-fancy

Blog: CEO's Corner

agsdix-fas fa-code

Blog: Tech Talk

Blog: Product Releases

agsdix-fas fa-chalkboard-teacher

Blog: Viewing

Blog: Conversion

arrow left circle icon Blog: Tech Talk

Converting a Microsoft Office File to a PDF File

by | Apr 24, 2012

Snowbound Software’s RasterMaster for the Java Platform includes the ability to convert a Microsoft Office file to a PDF. To convert a Word or Excel document to a PDF, you can create a byte array that will be in the PDF format. The IMG_save_bitmap(int initial_size, int buff_inc, int comp_type, int data_size[], int error[]) and the IMG_save_bitmap(String st, int comp_type) methods allow you to save your Word or Excel document as a PDF.

 IMG_save_bitmap(int, int, int, int)

This method is designed to allow saving to a byte array without knowing or guessing the final size of the compressed image or document. First, the initial size parameter is allocated. If the output data saved becomes larger than the initial size, then the buffer is reallocated to initial_size plus the increment size specified by buff_inc. Each time the output data becomes larger than the current buffer size when saving, the buffer is increased in size by the increment size. The caller must be careful in choosing the buffer increment size. If the buffer increment is too small, multiple reallocations will cause the saving process to be slow. If it is too large, too much memory will be allocated.

Note: We recommend an increment size of 10-25% of the initial buffer size.

Group 4 compression found in TIFF and AFP file formats typically compress at a rate of 10:1. You can choose an initial size of 1/8 to 1/10 of the uncompressed size.

A JPEG file format typically compresses at a rate of 10:1.

An LZW file format found in TIFF and GIF file formats compress at a rate of about 3:1. A .zip or flate file found in a PNG file format also compresses at a rate of about 3:1.

Note: Compression results for your images may vary. For best results, test a number of images to see what the resultant output size will be. Also, it is suggested to test out smaller and larger increment sizes to find the best level of performance.

The following shows the IMG_save_bitmap(int, int, int, int) method syntax and variable descriptions:

Syntax

int IMG_save_bitmap(int initial_size, int buff_inc, int comp_type, int error[]);

Remark

The table below lists the IMG_save_bitmap(int, int, int, int) method variable descriptions.

VariableDescription
initial_sizeThe buffer is initially allocated to this size exactly.
buff_incThe amount to grow the buffer if needed.
comp_typeOutput file format to write.
errorReturns the size of the data. If the value is less than zero, it is an error code.

Returns

Integer. Any positive value (as well as 0) is a valid return.

IMG_save_bitmap(String, int)

This method saves the current Snowbnd image object to the format specified by comp_type. The string value is the output file.

TIFF is a multi-page file format. If the image name already exists, a new page or image is appended to the local file, leaving the current images unchanged. If the file does not exist, it is created with only one page.

Note: Only applications and signed applets can save to a file.

The following shows the IMG_save_bitmap(String, int) method syntax and variable descriptions:

Syntax

int IMG_save_bitmap(String st, int comp_type);

Remark

The table below lists the IMG_save_bitmap(String, int) method variable descriptions.

VariableDescription
stOutput file name in which to save.
comp_typewrite.Output file format to 

Returns

Integer. Any positive value (as well as 0) is a valid return.