Q:
I would like to open other image types (such as JPEG, PNG, and TIFF)
besides PDF.
In PDFView sample project I can see how to open PDF, but how can I
open other image types?
----
A:
You can use PDFNet SDK to add interactive viewing support for other
image types besides PDF.
For example, the following code illustrates how pdftron.PDF.PDFView
class can be used to view TIFF, BMP, GIF, PNG, JPEG, JPEG2000,
JBIG2, ... (and of course PDF).
The idea is to place the image on a blank PDF document prior to
calling pdfview.SetDoc(temp_doc).
// Based on PDFView and AddImageTest sample projects.
public bool OpenImage(string filename) {
try
{
this.pdfDoc = new PDFDoc(); // create new document
ElementBuilder f = new ElementBuilder();
ElementWriter writer = new ElementWriter();page
Page page = this.pdfDoc.PageCreate(); // Add a blank page
writer.Begin(page);
// Add image to the document.
pdftron.PDF.Image img = pdftron.PDF.Image.Create(this.pdfDoc,
filename);
// get image rectangle
Rect box = new Rect(0, 0, img.GetImageWidth(),
img.GetImageHeight());
// set crop and media box of this page to fit with the image
page.SetCropBox(box);
page.SetMediaBox(box);
// create the image element and add it to the page
int width = img.GetImageWidth();
int height = img.GetImageHeight();
int offsetX = 0;
int offsetY = 0;
Element element = f.CreateImage(img, new Matrix2D(width, 0, 0,
height, offsetX, offsetY));
writer.WritePlacedElement(element);
writer.End(); // Finish writing to the page
this.pdfDoc.PagePushBack(page);
this.pdfView.SetDoc(this.pdfDoc);
return true;
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
return false;
}
}