« More notes | Home | MBS Real Studio Plugi… »


We have a new convenience function in DynaPDF. It's RenderPageToImage. Here is some example code:
dim pdf as new MyDynapdfMBS // where to get PDF pages dim f as FolderItem = SpecialFolder.Desktop.Child("test.pdf") // where to write dim t as FolderItem = SpecialFolder.Desktop.Child("test.jpg") pdf.SetLicenseKey "Pro" // For this example you can use a Pro or Enterprise License call pdf.CreateNewPDF nil call pdf.SetImportFlags(pdf.kifImportAll + pdf.kifImportAsPage) // open file call pdf.OpenImportFile(f,0,"") // add page call pdf.Append // import the page call pdf.ImportPageEx(1,1.0,1.0) call pdf.EndPage // render the page call pdf.RenderPageToImage(1, t, 72, ImageView1.Width, ImageView1.Height, DynaPDFRasterImageMBS.krfDefault,
DynaPDFRasterizerMBS.kpxfRGB, DynaPDFMBS.kcfJPEG, DynaPDFMBS.kifmJPEG)
Now as you see, we create an in memory PDF object with CreateNewPDF and passing nil. We set import flags to get all page items and to import page as page and not as template. Next we open the import file. This is now the initialization. You can keep the PDF object in memory for use later. To get a page to a JPG file, we add a page and import a page replacing the current one. This way we have now the first page of the source PDF in memory. We close page and start rendering. This little function takes a few parameters. First the page number of the current in memory PDF you want to render. In our example, this is the first page. Be aware that if we imported page 5 of the PDF file, the in memory page number would still be one. Next it takes a folderitem for the destination path. We also pass width and height of the target size. Next we can give some render options, but we simply pass default. We use RGB format, a JPEG compression and a JPEG file format. Done.
If you run the code with our plugins, you can see the rendered page in the jpg file. Cool, isn't it?

Update: If you pass nil for the file parameter, the image is created in memory. You call GetImageBuffer to get the data and FreeImageBuffer to release memory. The biggest plugin in space...
30 10 11 - 17:12