Frequently Asked Question
How to create an image page? (Windows)
Last Updated 11 months ago
To create a new image page, you can use the following code (premium license is needed):
StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile newFile = await storageFolder.CreateFileAsync("new.pdf", CreationCollisionOption.ReplaceExisting); IRandomAccessStream stream = await newFile.OpenAsync(FileAccessMode.ReadWrite); PDFDoc mNewDoc = new PDFDoc(); if (mNewDoc.Create(stream) == PDF_ERROR.err_ok) { float width = 297f, height = 210f; mNewDoc.SetCahce(storageFolder.Path + "\\new.dat"); PDFPage page = mNewDoc.NewPage(0, width, height); StorageFile imageFile = await storageFolder.GetFileAsync("bitmap.jpg"); IRandomAccessStream streamImage = await imageFile.OpenAsync(FileAccessMode.Read); WriteableBitmap writeableBitmap = new WriteableBitmap(1, 1); writeableBitmap.SetSource(streamImage); PDFDocImage image = mNewDoc.NewImage(writeableBitmap, true); if (image != null) { PDFPageImage pageImage = page.AddResImage(image); if (pageImage != null) { PDFPageContent pageContent = new PDFPageContent(); pageContent.GSSave(); PDFMatrix matrix = new PDFMatrix(width, height, 0, 0); pageContent.GSSetMatrix(matrix); pageContent.DrawImage(pageImage); pageContent.GSRestore(); page.AddContent(pageContent, true); page.Close(); } } mNewDoc.Save(); mNewDoc.Close(); }