图片转换(C++)

 图片转换 (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页面转换为位图文件

#include "include/common/fs_common.h"
#include "include/common/fs_image.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"
#include "include/common/fs_render.h"
using namespace foxit;
using namespace foxit::common;
using namespace pdf;

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

// Get page count.
int nPageCount = doc.GetPageCount();
for(int i=0;i<nPageCount;i++) {
 PDFPage page = doc.GetPage(i);

 // Parse page.
 page.StartParse(foxit::pdf::PDFPage::e_ParsePageNormal, NULL, false);

 int width = static_cast<int>(page.GetWidth());
 int height = static_cast<int>(page.GetHeight());
 Matrix matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation());

 // Prepare a bitmap for rendering.
 Bitmap bitmap(width, height, foxit::common::Bitmap::e_DIBArgb, NULL, 0);
 bitmap.FillRect(0xFFFFFFFF, NULL);

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

 如何将图片转换为PDF文件

#include "include/common/fs_common.h"
#include "include/common/fs_image.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace foxit::common;
using namespace pdf;

Image image(input_file);
int count = image.GetFrameCount();

PDFDoc doc;
for (int i = 0; i < count; i++) {
 PDFPage page = doc.InsertPage(i);
 page.StartParse(foxit::pdf::PDFPage::e_ParsePageNormal, NULL, false);
 // Add image to page.
 page.AddImage(image, i, PointF(0, 0), page.GetWidth(), page.GetHeight(), true);
}

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

这篇文章有用吗?

相关文章