彩票走势图

如何使用eDocEngine VCL将TIFF转换为PDF

原创|其它|编辑:郝浩|2012-10-15 16:57:44.000|阅读 489 次

概述:讲述了如何使用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@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP