图片转换(.NET)

图片转换 (Image Conversion)

Foxit PDF SDK提供了PDF文件和图片之间进行转换的APIs. 应用程序可以轻松地实现图片创建和图片转换等功能,支持如下的图片格式:BMP、TIFF、PNG、JPX、JPEG和 GIF。通过Foxit PDF SDK,PDF文件和支持的图片格式 (除了GIF) 之间可以互相转换。Foxit PDF SDK只支持将GIF图片转换为PDF文件。

Example:

如何将PDF页面转换为位图文件

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using System.Drawing;

// Assuming PDFDoc doc has been loaded.
...

Image image = new Image();

// Get page count
int nPageCount = doc.GetPageCount();
for(int i=0;i<nPageCount;i++)
{
   using (PDFPage page = doc.GetPage(i))
   {
      // Parse page.
      page.StartParse((int)foxit.pdf.PDFPage.ParseFlags.e_ParsePageNormal, null, false);

      int width = (int)(page.GetWidth());
      int height = (int)(page.GetHeight());
      Matrix2D matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation());

      // Prepare a bitmap for rendering.
      System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
      Graphics draw = Graphics.FromImage(bitmap);
      draw.Clear(Color.White);

      // Render page
      Renderer render = new Renderer(bitmap, false);
      render.StartRender(page, matrix, null);
      image.AddFrame(bitmap);
      }
}
...

如何将图片转换为PDF文件

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;
using System.Drawing;

// Assuming PDFDoc doc has been loaded.
...
Image image = new Image(input_file);
int count = image.GetFrameCount();

for (int i = 0; i < count; i++) {
    PDFPage page = doc.InsertPage(i, PDFPage.Size.e_SizeLetter);
    page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false);

    // Add image to page
    page.AddImage(image, i, new PointF(0, 0), page.GetWidth(), page.GetHeight(), true);
}

doc.SaveAs(output_file, (int)PDFDoc.SaveFlags.e_SaveFlagNoOriginal);
...
更新于 2020年4月22日

这篇文章有用吗?

相关文章