//Create a new PDF document.PdfDocumentdoc=newPdfDocument();//Add a page to the document.PdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image from the disk.PdfBitmapimage=newPdfBitmap("Autumn Leaves.jpg");//Draw the imagegraphics.DrawImage(image,0,0);//Save the document.doc.Save("Output.pdf");//Close the document.doc.Close(true);

'Create a new PDF document.DimdocAsNewPdfDocument()'Add a page to the document.DimpageAsPdfPage=doc.Pages.Add()'Create PDF graphics for the pageDimgraphicsAsPdfGraphics=page.Graphics'Load the image from the disk.DimimageAsNewPdfBitmap("Autumn Leaves.jpg")'Draw the imagegraphics.DrawImage(image,0,0)'Save the document.doc.Save("Output.pdf")'Close the document.doc.Close(True)

//Create a new PDF document.PdfDocumentdoc=newPdfDocument();//Add a page to the document.PdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as stream from the disk.StreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Data.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();awaitdoc.SaveAsync(stream);//Close the document.doc.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(stream,"Output.pdf");

//Create a new PDF document.PdfDocumentdoc=newPdfDocument();//Add a page to the document.PdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image from the disk.FileStreamimageStream=newFileStream("Autumn Leaves.jpg",FileMode.Open,FileAccess.Read);PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Creating the stream objectMemoryStreamstream=newMemoryStream();//Save the document as streamdoc.Save(stream);//If the position is not set to '0' then the PDF will be empty.stream.Position=0;//Close the document.doc.Close(true);//Defining the ContentType for pdf file.stringcontentType="application/pdf";//Define the file name.stringfileName="Output.pdf";//Creates a FileContentResult object by using the file contents, content type, and file name.returnFile(stream,contentType,fileName);

//Create a new PDF document.PdfDocumentdoc=newPdfDocument();//Add a page to the document.PdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as streamStreamimageStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();doc.Save(stream);//Close the document.doc.Close(true);//Save the stream into pdf file//The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.if(Device.OS==TargetPlatform.WinPhone||Device.OS==TargetPlatform.Windows){Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf","application/pdf",stream);}else{Xamarin.Forms.DependencyService.Get<ISave>().Save("Output.pdf","application/pdf",stream);}

Inserting an image in an existing document

You can also add images into an existing PDF document using the below code snippet.

//Load a PDF document.PdfLoadedDocumentdoc=newPdfLoadedDocument("input.pdf");//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image from the diskPdfBitmapimage=newPdfBitmap("Autumn Leaves.jpg");//Draw the imagegraphics.DrawImage(image,0,0);//Save the document.doc.Save("Output.pdf");//Close the document.doc.Close(true);

'Load a PDF document.DimdocAsNewPdfLoadedDocument("input.pdf")'Get first page from documentDimpageAsPdfLoadedPage=TryCast(doc.Pages(0),PdfLoadedPage)'Create PDF graphics for the pageDimgraphicsAsPdfGraphics=page.Graphics'Load the image from the diskDimimageAsNewPdfBitmap("Autumn Leaves.jpg")'Draw the imagegraphics.DrawImage(image,0,0)'Save the document.doc.Save("Output.pdf")'Close the document.doc.Close(True)

//Create the file open pickervarpicker=newFileOpenPicker();picker.FileTypeFilter.Add(".pdf");//Browse and chose the fileStorageFilefile=awaitpicker.PickSingleFileAsync();//Creates an empty PDF loaded document instancePdfLoadedDocumentdoc=newPdfLoadedDocument();//Loads or opens an existing PDF document through Open method of PdfLoadedDocument classawaitdoc.OpenAsync(file);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as streamStreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Data.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();awaitdoc.SaveAsync(stream);//Close the document.doc.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(stream,"Output.pdf");

//Load the PDF documentFileStreamdocStream=newFileStream("Input.pdf",FileMode.Open,FileAccess.Read);PdfLoadedDocumentdoc=newPdfLoadedDocument(docStream);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image from the diskFileStreamimageStream=newFileStream("Autumn Leaves.jpg",FileMode.Open,FileAccess.Read);PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Creating the stream objectMemoryStreamstream=newMemoryStream();//Save the document as streamdoc.Save(stream);//If the position is not set to '0' then the PDF will be empty.stream.Position=0;//Close the document.doc.Close(true);//Defining the ContentType for pdf file.stringcontentType="application/pdf";//Define the file name.stringfileName="Output.pdf";//Creates a FileContentResult object by using the file contents, content type, and file name.returnFile(stream,contentType,fileName);

//Load the file as streamStreamdocStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.input.pdf");PdfLoadedDocumentdoc=newPdfLoadedDocument(docStream);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as streamStreamimageStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();doc.Save(stream);//Close the document.doc.Close(true);//Save the stream into pdf file//The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.if(Device.OS==TargetPlatform.WinPhone||Device.OS==TargetPlatform.Windows){Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf","application/pdf",stream);}else{Xamarin.Forms.DependencyService.Get<ISave>().Save("Output.pdf","application/pdf",stream);}

//Load a PDF document.PdfLoadedDocumentdoc=newPdfLoadedDocument("input.pdf");//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the imageStreamimageStream=File.OpenRead("Autumn Leaves.jpg");//Load the image from the streamPdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document.doc.Save("Output.pdf");//Close the document.doc.Close(true);

'Load a PDF document.DimdocAsNewPdfLoadedDocument("input.pdf")'Get first page from documentDimpageAsPdfLoadedPage=TryCast(doc.Pages(0),PdfLoadedPage)'Create PDF graphics for the pageDimgraphicsAsPdfGraphics=page.Graphics'Load the imageDimimageStreamAsStream=File.OpenRead("Autumn Leaves.jpg")'Load the image from the streamDimimageAsNewPdfBitmap(imageStream)'Draw the imagegraphics.DrawImage(image,0,0)'Save the document.doc.Save("Output.pdf")'Close the document.doc.Close(True)

//Create the file open pickervarpicker=newFileOpenPicker();picker.FileTypeFilter.Add(".pdf");//Browse and chose the fileStorageFilefile=awaitpicker.PickSingleFileAsync();//Creates an empty PDF loaded document instancePdfLoadedDocumentdoc=newPdfLoadedDocument();//Loads or opens an existing PDF document through Open method of PdfLoadedDocument classawaitdoc.OpenAsync(file);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as streamStreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Data.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();awaitdoc.SaveAsync(stream);//Close the document.doc.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(stream,"Output.pdf");

//Load the PDF documentFileStreamdocStream=newFileStream("Input.pdf",FileMode.Open,FileAccess.Read);PdfLoadedDocumentdoc=newPdfLoadedDocument(docStream);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image from the diskFileStreamimageStream=newFileStream("Autumn Leaves.jpg",FileMode.Open,FileAccess.Read);PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Creating the stream objectMemoryStreamstream=newMemoryStream();//Save the document as streamdoc.Save(stream);//If the position is not set to '0' then the PDF will be empty.stream.Position=0;//Close the document.doc.Close(true);//Defining the ContentType for pdf file.stringcontentType="application/pdf";//Define the file name.stringfileName="Output.pdf";//Creates a FileContentResult object by using the file contents, content type, and file name.returnFile(stream,contentType,fileName);

//Load the file as streamStreamdocStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.input.pdf");PdfLoadedDocumentdoc=newPdfLoadedDocument(docStream);//Get first page from documentPdfLoadedPagepage=doc.Pages[0]asPdfLoadedPage;//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the image as streamStreamimageStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Draw the imagegraphics.DrawImage(image,0,0);//Save the document as stream.MemoryStreamstream=newMemoryStream();doc.Save(stream);//Close the document.doc.Close(true);//Save the stream into pdf file//The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.if(Device.OS==TargetPlatform.WinPhone||Device.OS==TargetPlatform.Windows){Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf","application/pdf",stream);}else{Xamarin.Forms.DependencyService.Get<ISave>().Save("Output.pdf","application/pdf",stream);}

Inserting a vector image

Essential PDF supports adding Metafile vector image. During the insertion, Metafile graphics will be transformed to native PDF graphics that supports text selection and searching. The following types of Metafiles are supported in Essential PDF.

// Create a PDF Document.PdfDocumentdoc=newPdfDocument();//Add pages to the documentPdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Create the layout formatPdfMetafileLayoutFormatformat=newPdfMetafileLayoutFormat();//Split text and image between pagesformat.SplitImages=true;format.SplitTextLines=true;//Create a Metafile instancePdfMetafilemetaChart=newPdfMetafile("MetaChart.emf");//Draw the Metafile in the pagemetaChart.Draw(page,PointF.Empty,format);//Save the documentdoc.Save("Output.pdf");//Close the documentdoc.Close(true);

'Create a PDF Document.DimdocAsNewPdfDocument()'Add pages to the documentDimpageAsPdfPage=doc.Pages.Add()'Create PDF graphics for the pageDimgraphicsAsPdfGraphics=page.Graphics'Create the layout formatDimformatAsNewPdfMetafileLayoutFormat()'Split text and image between pagesformat.SplitImages=Trueformat.SplitTextLines=True'Create a Metafile instanceDimmetaChartAsNewPdfMetafile("MetaChart.emf")'Draw the Metafile in the pagemetaChart.Draw(page,PointF.Empty,format)'Save the documentdoc.Save("Output.pdf")'Close the documentdoc.Close(True)

Working with image masking

//Create a PDF documentPdfDocumentdoc=newPdfDocument();//Add pages to the documentPdfPagepage=doc.Pages.Add();//Create PDF graphics for the pagePdfGraphicsgraphics=page.Graphics;//Load the TIFF imagePdfBitmapimage=newPdfBitmap("image.tif");//Create masking imagePdfImageMaskmask=newPdfImageMask(newPdfBitmap("mask.bmp"));image.Mask=mask;//Draw the imagegraphics.DrawImage(image,0,0);//Saves the documentdoc.Save("Output.pdf");//Close the documentdoc.Close(true);

'Create a PDF documentDimdocAsNewPdfDocument()'Add pages to the documentDimpageAsPdfPage=doc.Pages.Add()'Create PDF graphics for the pageDimgraphicsAsPdfGraphics=page.Graphics'Load the TIFF imageDimimageAsNewPdfBitmap("image.tif")'Create masking imageDimmaskAsNewPdfImageMask(NewPdfBitmap("mask.bmp"))image.Mask=mask'Draw the imagegraphics.DrawImage(image,0,0)'Saves the documentdoc.Save("Output.pdf")'Close the documentdoc.Close(True)

Replacing Images in an existing PDF document

//Load the PDF documentPdfLoadedDocumentdoc=newPdfLoadedDocument(@"image.pdf");//Create an image instancePdfBitmapimage=newPdfBitmap(@"Autumn Leaves.jpg");//Replace the first image in the page.doc.Pages[0].ReplaceImage(0,image);//Save the documentdoc.Save("Output.pdf");//Close the documentdoc.Close(true);

'Load the PDF documentDimdocAsNewPdfLoadedDocument("image.pdf")'Create an image instanceDimimageAsNewPdfBitmap("Autumn Leaves.jpg")'Replace the first image in the page.doc.Pages(0).ReplaceImage(0,image)'Save the documentdoc.Save("Output.pdf")'Close the documentdoc.Close(True)

Image Pagination

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add new pagePdfPagepage=doc.Pages.Add();//Load a bitmapPdfBitmapimage=newPdfBitmap("input.jpg");//Set layout property to make the element break across the pages.PdfLayoutFormatformat=newPdfLayoutFormat();format.Break=PdfLayoutBreakType.FitPage;format.Layout=PdfLayoutType.Paginate;//Draw imageimage.Draw(page,20,400,format);//Save the PDFdoc.Save("output.pdf");doc.Close(true);

'Create DocumentDimdocAsNewPdfDocument()'Add new pageDimpageAsPdfPage=doc.Pages.Add()'Load a bitmapDimimageAsNewPdfBitmap("input.jpg")'Set layout property to make the element break across the pages.DimformatAsNewPdfLayoutFormat()format.Break=PdfLayoutBreakType.FitPageformat.Layout=PdfLayoutType.Paginate'Draw imageimage.Draw(page,20,400,format)'Save the PDFdoc.Save("output.pdf")doc.Close(True)

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add new pagePdfPagepage=doc.Pages.Add();//Load the image as streamStreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Data.Assets.Autumn Leaves.jpg");//Load a bitmapPdfBitmapimage=newPdfBitmap(imageStream);//Set layout property to make the element break across the pages.PdfLayoutFormatformat=newPdfLayoutFormat();format.Break=PdfLayoutBreakType.FitPage;format.Layout=PdfLayoutType.Paginate;//Draw imageimage.Draw(page,20,400,format);//Save the document as stream.MemoryStreamstream=newMemoryStream();awaitdoc.SaveAsync(stream);//Close the document.doc.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(stream,"Output.pdf");

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add new pagePdfPagepage=doc.Pages.Add();//Load a bitmapFileStreamimageStream=newFileStream("Autumn Leaves.jpg",FileMode.Open,FileAccess.Read);PdfBitmapimage=newPdfBitmap(imageStream);//Set layout property to make the element break across the pages.PdfLayoutFormatformat=newPdfLayoutFormat();format.Break=PdfLayoutBreakType.FitPage;format.Layout=PdfLayoutType.Paginate;//Draw imageimage.Draw(page,20,400,format);//Creating the stream objectMemoryStreamstream=newMemoryStream();//Save the document as streamdoc.Save(stream);//If the position is not set to '0' then the PDF will be empty.stream.Position=0;//Close the document.doc.Close(true);//Defining the ContentType for pdf file.stringcontentType="application/pdf";//Define the file name.stringfileName="Output.pdf";//Creates a FileContentResult object by using the file contents, content type, and file name.returnFile(stream,contentType,fileName);

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add new pagePdfPagepage=doc.Pages.Add();//Load a bitmapStreamimageStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.Data.Autumn Leaves.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//Set layout property to make the element break across the pages.PdfLayoutFormatformat=newPdfLayoutFormat();format.Break=PdfLayoutBreakType.FitPage;format.Layout=PdfLayoutType.Paginate;//Draw imageimage.Draw(page,20,400,format);//Save the document as stream.MemoryStreamstream=newMemoryStream();doc.Save(stream);//Close the document.doc.Close(true);//Save the stream into pdf file//The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.if(Device.OS==TargetPlatform.WinPhone||Device.OS==TargetPlatform.Windows){Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf","application/pdf",stream);}else{Xamarin.Forms.DependencyService.Get<ISave>().Save("Output.pdf","application/pdf",stream);}

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add a new pagePdfPagepage=doc.Pages.Add();//Load a bitmapPdfBitmapimage=newPdfBitmap("input.jpg");//save the current graphics statePdfGraphicsStatestate=page.Graphics.Save();//Translate the coordinate system to the required positionpage.Graphics.TranslateTransform(20,100);//Apply transparencypage.Graphics.SetTransparency(0.5f);//Rotate the coordinate systempage.Graphics.RotateTransform(-45);// Draw imageimage.Draw(page,0,0);//Restore the graphics statepage.Graphics.Restore(state);//Save the PDFdoc.Save("output.pdf");doc.Close(true);

'Create DocumentDimdocAsNewPdfDocument()'Add a new pageDimpageAsPdfPage=doc.Pages.Add()'Load a bitmapDimimageAsNewPdfBitmap("input.jpg")'save the current graphics stateDimstateAsPdfGraphicsState=page.Graphics.Save()'Translate the coordinate system to the required positionpage.Graphics.TranslateTransform(20,100)'Apply transparencypage.Graphics.SetTransparency(0.5F)'Rotate the coordinate systempage.Graphics.RotateTransform(-45)' Draw imageimage.Draw(page,0,0)'Restore the graphics statepage.Graphics.Restore(state)'Save the PDFdoc.Save("output.pdf")doc.Close(True)

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add new pagePdfPagepage=doc.Pages.Add();//Load the image as streamStreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Data.Assets.input.jpg");//Load a bitmap.PdfBitmapimage=newPdfBitmap(imageStream);//save the current graphics statePdfGraphicsStatestate=page.Graphics.Save();//Translate the coordinate system to the required positionpage.Graphics.TranslateTransform(20,100);//Apply transparencypage.Graphics.SetTransparency(0.5f);//Rotate the coordinate systempage.Graphics.RotateTransform(-45);// Draw imageimage.Draw(page,0,0);//Restore the graphics statepage.Graphics.Restore(state);//Save the document as stream.MemoryStreamstream=newMemoryStream();awaitdoc.SaveAsync(stream);//Close the document.doc.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(stream,"Output.pdf");

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add a new pagePdfPagepage=doc.Pages.Add();//Load a image as streamFileStreamimageStream=newFileStream("input.jpg",FileMode.Open,FileAccess.Read);//Load a bitmap.PdfBitmapimage=newPdfBitmap(imageStream);//save the current graphics statePdfGraphicsStatestate=page.Graphics.Save();//Translate the coordinate system to the required positionpage.Graphics.TranslateTransform(20,100);//Apply transparencypage.Graphics.SetTransparency(0.5f);//Rotate the coordinate systempage.Graphics.RotateTransform(-45);// Draw imageimage.Draw(page,0,0);//Restore the graphics statepage.Graphics.Restore(state);//Creating the stream objectMemoryStreamstream=newMemoryStream();//Save the document as streamdoc.Save(stream);//If the position is not set to '0' then the PDF will be empty.stream.Position=0;//Close the document.doc.Close(true);//Defining the ContentType for pdf file.stringcontentType="application/pdf";//Define the file name.stringfileName="Output.pdf";//Creates a FileContentResult object by using the file contents, content type, and file name.returnFile(stream,contentType,fileName);

//Create DocumentPdfDocumentdoc=newPdfDocument();//Add a new pagePdfPagepage=doc.Pages.Add();//Load a bitmapStreamimageStream=typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.input.jpg");PdfBitmapimage=newPdfBitmap(imageStream);//save the current graphics statePdfGraphicsStatestate=page.Graphics.Save();//Translate the coordinate system to the required positionpage.Graphics.TranslateTransform(20,100);//Apply transparencypage.Graphics.SetTransparency(0.5f);//Rotate the coordinate systempage.Graphics.RotateTransform(-45);// Draw imageimage.Draw(page,0,0);//Restore the graphics statepage.Graphics.Restore(state);//Save the document as stream.MemoryStreamstream=newMemoryStream();doc.Save(stream);//Close the document.doc.Close(true);//Save the stream into pdf file//The operation in Save under Xamarin varies between Windows Phone, Android and iOS platforms. Please refer PDF/Xamarin section for respective code samples.if(Device.OS==TargetPlatform.WinPhone||Device.OS==TargetPlatform.Windows){Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Output.pdf","application/pdf",stream);}else{Xamarin.Forms.DependencyService.Get<ISave>().Save("Output.pdf","application/pdf",stream);}

Converting multi page TIFF to PDF

Multi frame TIFF image can be converted to PDF document. This can be done by accessing each frame of the multi frame TIFF image and rendering it in each page of the PDF document.

//Create a PDF documentPdfDocumentpdfDocument=newPdfDocument();//Add a section to the PDF documentPdfSectionsection=pdfDocument.Sections.Add();//Declare the PDF pagePdfPagepage;//Declare PDF page graphicsPdfGraphicsgraphics;//Load multi frame TIFF imagePdfBitmaptiffImage=newPdfBitmap("image.tiff");//Get the frame countintframeCount=tiffImage.FrameCount;//Access each frame draw into the pagefor(inti=0;i<frameCount;i++){page=section.Pages.Add();section.PageSettings.Margins.All=0;graphics=page.Graphics;tiffImage.ActiveFrame=i;graphics.DrawImage(tiffImage,0,0,page.GetClientSize().Width,page.GetClientSize().Height);}//Save and close the documentpdfDocument.Save("Sample.pdf");pdfDocument.Close(true);

'Create a PDF documentDimpdfDocumentAsNewPdfDocument()'Add a section to the PDF documentDimsectionAsPdfSection=pdfDocument.Sections.Add()'Declare the PDF pageDimpageAsPdfPage'Declare PDF page graphicsDimgraphicsAsPdfGraphics'Load multi frame TIFF imageDimtiffImageAsNewPdfBitmap("image.tiff")'Get the frame countDimframeCountAsInteger=tiffImage.FrameCount'Access each frame draw into the pageForiAsInteger=0ToframeCount-1page=section.Pages.Add()section.PageSettings.Margins.All=0graphics=page.GraphicstiffImage.ActiveFrame=igraphics.DrawImage(tiffImage,0,0,page.GetClientSize().Width,page.GetClientSize().Height)Next'Save and close the documentpdfDocument.Save("Sample.pdf")pdfDocument.Close(True)

//Create a PDF documentPdfDocumentpdfDocument=newPdfDocument();//Add a section to the PDF documentPdfSectionsection=pdfDocument.Sections.Add();//Declare the PDF pagePdfPagepage;//Declare PDF page graphicsPdfGraphicsgraphics;//Load multi frame TIFF imageStreamimageStream=typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.image.tiff");PdfBitmaptiffImage=newPdfBitmap(imageStream);//Get the frame countintframeCount=tiffImage.FrameCount;//Access each frame draw into the pagefor(inti=0;i<frameCount;i++){page=section.Pages.Add();section.PageSettings.Margins.All=0;graphics=page.Graphics;tiffImage.ActiveFrame=i;graphics.DrawImage(tiffImage,0,0,page.GetClientSize().Width,page.GetClientSize().Height);}MemoryStreammemoryStream=newMemoryStream();//Save the document.awaitpdfDocument.SaveAsync(memoryStream);//Close the documents.pdfDocument.Close(true);//Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples.Save(memoryStream,"Sample.pdf");