Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







PDFtoolkit VCL works on existing PDF documents. You don't create new PDF documents with it. But, it does have a method that allows you to insert a blank page to an existing PDF document.
public procedure InsertBlankPageAt(
APageNumber: Integer;
PageWidth: Double;
PageHeight: Double
);
So, you could create a new PDF document from scratch by:
InsertBlankPageAt() method; andYes, it is quite a useful method. In this article, we will not go in that direction. Instead, we will use the InsertBlankPageAt() method to create pages that will hold images exported from a multi-page TIFF image.
Following is the source code of a Delphi console application. It uses Erik Van Bilsen's Delphi GDI+ library to extract frames from a multipage TIFF image. The extracted images are then rendered on to a blank PDF page inserted using InsertBlankPageAt().
program TIFF_To_PDF_With_eDocEngine;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes, Windows, Graphics, jpeg,
GdiPlus, GdiPlusHelpers, // Using Erik van Bilsen's Delphi GDI+ library
gtPDFClasses, gtCstPDFDoc, gtExPDFDoc, gtExProPDFDoc, gtPDFDoc;
var
TIFFImage: IGPImage;
PageGuid: TGUID;
Bitmap1: TBitmap;
FrameCount, PageCount, I, J: Integer;
PageRange: string;
PageDimensions: TGPSizeF;
gtPDFDocument1: TgtPDFDocument;
gtImageWatermarkTemplate1: TgtImageWatermarkTemplate;
begin
try
// Load the mult-frame TIFF image
TIFFImage := TGPBitmap.FromFile('multi_page.tiff');
// Obtain the number of frames in the TIFF image
PageGuid := FrameDimensionPage;
FrameCount := TIFFImage.GetFrameCount(PageGuid);
if PageCount > 0 then begin
// Load an existing PDF document
gtPDFDocument1 := TgtPDFDocument.Create(nil);
gtPDFDocument1.LoadFromFile('input_doc.pdf');
// Find last page number
J := gtPDFDocument1.PageCount;
// Iterate through all frames in the TIFF image
for I := 0 to FrameCount - 1 do begin
// Select a frame
TIFFImage.SelectActiveFrame(PageGuid,I);
// Obtain dimensins of current frame
TIFFImage.GetPhysicalDimension(PageDimensions);
// Insert new page after last page - new page has same
// dimension as current frame of TIFF image
J := J + 1;
gtPDFDocument1.InsertBlankPageAt(J,
PageDimensions.Width,
PageDimensions.Height);
// Save current frame to an temporary JPEG image
TIFFImage.Save('temp_frame.bmp', TGPImageFormat.Bmp);
// Load temporary image
Bitmap1 := TBitmap.Create;
Bitmap1.LoadFromFile('temp_frame.bmp');
// Render image on the new PDF page as an image watermark
gtImageWatermarkTemplate1 := TgtImageWatermarkTemplate.Create;
with gtImageWatermarkTemplate1 do begin
X := 0;
Y := 0;
Image := Bitmap1;
HorizPos := hpCenter;
VertPos := vpMiddle;
end;
gtPDFDocument1.InsertWatermark(gtImageWatermarkTemplate1, IntToStr(J));
Bitmap1.FreeImage;
end;
// Save modified PDF document to a new file
gtPDFDocument1.SaveToFile('output_doc.pdf');
// Free resources
gtPDFDocument1.Reset;
end;
except
on E: Exception do begin
Writeln(E.ClassName, ': ', E.Message);
Readln;
end;
end;
end.
The above code used the following PDF document as the input file.

Bilsen's Delphi GDI+ library was used for extract frames from a multipage TIFF image.

After running the code, frames from the TIFF image were rendered new pages inserted into the PDF document.

---o0O0o---
| Our Developer Tools | |
|---|---|
eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).