原創|其它|編輯:郝浩|2012-10-15 16:57:44.000|閱讀 524 次
概述:講述了如何使用eDocEngine VCL將TIFF轉換為PDF的步驟。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
以下是使用eDocEngine VCL 將TIFF圖像轉換為一個PDF文檔的Delphi代碼示例。
program TIFF_To_PDF_With_eDocEngine; {$APPTYPE CONSOLE} uses SysUtils, Classes, Windows, Graphics, jpeg, GdiPlus, GdiPlusHelpers, // Using Erik van Bilsen's Delphi GDI+ library gtPDFDoc, gtCstPDFDoc, gtClasses3, gtCstDocEng, gtCstPlnEng, gtCstPDFEng, gtExPDFEng, gtPDFEng; var TIFFImage: IGPImage; PageGuid: TGUID; JPEGImage1: TJPEGImage; PageCount, I: Integer; PageDimensions: TGPSizeF; gtPDFEngine1: TgtPDFEngine; 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; PageCount := TIFFImage.GetFrameCount(PageGuid); if PageCount > 0 then begin // Create PDF engine gtPDFEngine1 := TgtPDFEngine.Create(nil); gtPDFEngine1.FileName := 'multi_page.pdf'; gtPDFEngine1.MeasurementUnit := muPixels; gtPDFEngine1.Preferences.ShowSetupDialog := False; gtPDFEngine1.Page.PaperSize := Custom; // Iterate through all frames in the TIFF image for I := 0 to PageCount - 1 do begin // Select a frame TIFFImage.SelectActiveFrame(PageGuid,I); // Obtain dimensins of current frame TIFFImage.GetPhysicalDimension(PageDimensions); // Set PDF engine page dimension same as // that of current frame of the TIFF image gtPDFEngine1.Page.Width := PageDimensions.Width; gtPDFEngine1.Page.Height := PageDimensions.Height; // Save current frame to an temporary JPEG image TIFFImage.Save('temp_frame.jpg', TGPImageFormat.Jpeg); if i = 0 then begin // Create first PDF page gtPDFEngine1.BeginDoc; // Do this only after setting page dimensions end else begin // Create next PDF page gtPDFEngine1.NewPage; end; // Load temporary JPEG image JPEGImage1 := TJPEGImage.Create; JPEGImage1.LoadFromFile('temp_frame.jpg'); // Render JPEG image on the current PDF page gtPDFEngine1.DrawImage(0,0, JPEGImage1); end; // Save PDF document to file gtPDFEngine1.EndDoc; end; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網