public Task ToPdf(Box box, Func <Size, FixedDocument> renderToXps, string fileName, PdfOptions options) { return(Task.Run(() => { var xpsFileName = fileName + EXT_XPS; var pdfPage = new PdfPage { Size = options.PageSize, Orientation = options.PageOrientation }; var width = pdfPage.Width.Inch * WPF_DPI; var height = pdfPage.Height.Inch * WPF_DPI; Application.Current.Dispatcher.Invoke(() => { var document = renderToXps(new Size(width, height)); var xpsd = new XpsDocument(xpsFileName, FileAccess.ReadWrite); var xw = XpsDocument.CreateXpsDocumentWriter(xpsd); xw.Write(document); xpsd.Close(); }); PdfSharp.Xps.XpsConverter.Convert(xpsFileName); File.Delete(xpsFileName); })); }
public Stream Convert(string html, PdfOptions pdfOptions = null) { var doc = new HtmlToPdfDocument() { GlobalSettings = { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings() { Top = 10,Bottom= 15, Left = 10, Right = 10 }, }, Objects = { new ObjectSettings() { PagesCount = true, HtmlContent = html, WebSettings = { DefaultEncoding = "utf-8", Background = true }, HeaderSettings ={ FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812}, }, }, }; byte[] pdf = _converter.Convert(doc); return(new MemoryStream(pdf)); }
/// <summary> /// TODO: Figure out why Creatinig PDF does not work in production. /// </summary> /// <param name="file"></param> static async Task createPDF(string file) { try { await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }); var page = await browser.NewPageAsync(); await page.SetViewportAsync(new ViewPortOptions { Width = 50000, Height = 50 }); NavigationOptions navOpts = new NavigationOptions(); navOpts.Timeout = 0; await page.GoToAsync(file, navOpts); PdfOptions options = new PdfOptions(); options.Width = 2000; options.Height = 1200; options.MarginOptions.Left = "100"; options.MarginOptions.Right = "100"; options.MarginOptions.Top = "50"; options.MarginOptions.Bottom = "50"; await page.PdfAsync(Path.Combine(Path.GetDirectoryName(location), Path.GetFileNameWithoutExtension(file) + ".pdf"), options); } catch (Exception e) { Debug.WriteLine(e.Message); } }
public static void Run() { // ExStart:CroppingEMFImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; // Load an existing image into an instance of EMF class using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { using (FileStream outputStream = new FileStream(dataDir + "CroppingEMFImage_out.pdf", FileMode.Create)) { // Based on the shift values, apply the cropping on image and Crop method will shift the image bounds toward the center of image image.Crop(30, 40, 50, 60); // Set height and width and Save the results to disk pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; image.Save(outputStream, pdfOptions); } } // ExEnd:CroppingEMFImage }
public static void Run() { //ExStart:ConvertSlidesToPdfNotes // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Conversion(); // Instantiate a Presentation object that represents a presentation file Presentation presentation = new Presentation(dataDir + "SelectedSlides.pptx"); Presentation auxPresentation = new Presentation(); ISlide slide = presentation.Slides[0]; auxPresentation.Slides.InsertClone(0, slide); // Setting Slide Type and Size //auxPresentation.SlideSize.SetSize(presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height,SlideSizeScaleType.EnsureFit); auxPresentation.SlideSize.SetSize(612F, 792F, SlideSizeScaleType.EnsureFit); PdfOptions pdfOptions = new PdfOptions(); INotesCommentsLayoutingOptions options = pdfOptions.NotesCommentsLayouting; options.NotesPosition = NotesPositions.BottomFull; auxPresentation.Save(dataDir + "PDFnotes_out.pdf", SaveFormat.Pdf, pdfOptions); //ExEnd:ConvertSlidesToPdfNotes }
public static void Run() { //ExStart:PenSupportInExport string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + "conic_pyramid.dxf"; CadImage cadImage = (CadImage)Image.Load(sourceFilePath); CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); PdfOptions pdfOptions = new PdfOptions(); // Here user can change default start cap and end cap of pens when exporting CadImage object to // image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf. // If user doesn't use PenOptions, system will use its own default pens (different in defferent places). rasterizationOptions.PenOptions = new PenOptions { StartCap = LineCap.Flat, EndCap = LineCap.Flat }; pdfOptions.VectorRasterizationOptions = rasterizationOptions; cadImage.Save(GetFileFromDesktop(MyDir + "9LHATT-A56_generated.pdf"), pdfOptions); //ExEnd:PenSupportInExport }
public static void Run() { // ExStart:CroppingByRectangleEMFImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; // Load an existing image into an instance of EMF class using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { using (FileStream outputStream = new FileStream(dataDir + "CroppingByRectangleEMFImage_out.pdf", FileMode.Create)) { // Create an instance of Rectangle class with desired size and Perform the crop operation on object of Rectangle class and Set height and width and Save the results to disk image.Crop(new Rectangle(30, 50, 100, 150)); pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; image.Save(outputStream, pdfOptions); } } // ExEnd:CroppingByRectangleEMFImage }
static void Main(string[] args) { //[C# Code Sample] // create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke; // create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; //Declare variables to store file paths for input and output images string filePath = @"E:\armstalker.emf"; string outPath = filePath + ".pdf"; //Load an existing image into an instance of EMF class using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath)) { using (FileStream outputStream = new FileStream(outPath, FileMode.Create)) { //Create an instance of Rectangle class with desired size //Perform the crop operation on object of Rectangle class image.Crop(new Aspose.Imaging.Rectangle(0, 4100, 10000, 1500)); // Set height and width pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; //Save the results to disk image.Save(outputStream, pdfOptions); } } }
public static void Run() { // ExStart:ConvertEMFToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); string[] filePaths = { "Picture1.emf" }; foreach (string filePath in filePaths) { string outPath = dataDir + filePath + "_out.pdf"; using (var image = (EmfImage)Image.Load(dataDir + filePath)) using (FileStream outputStream = new FileStream(outPath, FileMode.Create)) { if (!image.Header.EmfHeader.Valid) { throw new ImageLoadException(string.Format("The file {0} is not valid", outPath)); } EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions(); emfRasterization.PageWidth = image.Width; emfRasterization.PageHeight = image.Height; emfRasterization.BackgroundColor = Color.WhiteSmoke; PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterization; image.Save(outputStream, pdfOptions); } } // ExEnd:ConvertEMFToPDF }
public static void Run() { //ExStart:MeshSupport string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + ("meshes.dwg"); string outPath = MyDir + ("meshes.pdf"); using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageWidth = 1600; rasterizationOptions.PageHeight = 1600; rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D; rasterizationOptions.Layouts = new string[] { "Model" }; PdfOptions pdfOptions = new PdfOptions { VectorRasterizationOptions = rasterizationOptions }; { cadImage.Save(outPath, pdfOptions); } } //ExEnd:MeshSupport }
public async Task <OperationResult> IsPdfDocument(PdfOptions options) { var fileName = options.Source; if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName)) { return(InvalidArgument()); } try { var result = await Task.Run(() => service.PdfDocument(fileName)); return(Successful(result)); } catch (IOException ex) { return(FileAccessError(ex.Message)); } catch (SystemException ex) when(ex is UnauthorizedAccessException || ex is NotSupportedException) { return(InsufficientPermissions(ex.Message)); } catch (Exception ex) { return(GeneralFailure(ex.Message)); } }
void Test02() { var OFD = new OpenFileDialog(); if (OFD.ShowDialog() == DialogResult.OK) { var path = OFD.FileName; using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(path)) { var opt = new CadRasterizationOptions(); //opt.PageWidth = 1600; //opt.PageHeight = 1600; opt.AutomaticLayoutsScaling = true; opt.NoScaling = true; ImageOptionsBase pdfOpt = new PdfOptions(); pdfOpt.VectorRasterizationOptions = opt; image.Save(path + "_TEST.pdf", pdfOpt); } } }
public async Task <OperationResult> Unlock(PdfOptions options) { try { if (!ValidUnlockRequest(options)) { return(InvalidArgument()); } await Task.Run(() => service.Unlock(options)); return(Successful()); } catch (BadPasswordException ex) when(ex.Message == "PdfReader is not opened with owner password") { return(BadOwnerPassword()); } catch (BadPasswordException) { return(BadPassword()); } catch (IOException ex) { return(FileAccessError(ex.Message)); } catch (SystemException ex) when(ex is UnauthorizedAccessException || ex is NotSupportedException) { return(InsufficientPermissions(ex.Message)); } catch (Exception ex) { return(GeneralFailure(ex.Message)); } }
public async Task <OperationResult> Protect(PdfOptions options) { try { if (!ValidProtectOptions(options)) { return(InvalidArgument()); } await Task.Run(() => service.Protect(options)); return(Successful()); } catch (BadPasswordException) { return(BadPassword()); } catch (IOException ex) { return(FileAccessError(ex.Message)); } catch (SystemException ex) when(ex is UnauthorizedAccessException || ex is NotSupportedException) { return(InsufficientPermissions(ex.Message)); } catch (Exception ex) { return(GeneralFailure(ex.Message)); } }
public byte[] Generate(Guid applicationId, string baseUri) { //Changed to single or default to allow logging if no application is found Application application = _dataContext.Applications.SingleOrDefault(app => app.Id == applicationId); if (application != null) { //Correct substring to remove last character if (baseUri.EndsWith("/")) { baseUri = baseUri.Substring(0, baseUri.Length - 1); } string view = GetView(application, baseUri); var pdfOptions = new PdfOptions { PageNumbers = PageNumbers.Numeric, HeaderOptions = new HeaderOptions { HeaderRepeat = HeaderRepeat.FirstPageOnly, HeaderHtml = PdfConstants.Header } }; var pdf = _pdfGenerator.GenerateFromHtml(view, pdfOptions); return(pdf.ToBytes()); } else { _logger.LogWarning( $"No application found for id '{applicationId}'"); return(null); } }
public static void Run() { //ExStart:1 string SourceDir = RunExamples.GetDataDir_DWGDrawings(); string OutputDir = RunExamples.GetDataDir_Output(); using (Image cadDrawing = Image.Load(SourceDir + "Drawing11.dwg")) { var rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageWidth = cadDrawing.Size.Width; rasterizationOptions.PageHeight = cadDrawing.Size.Height; using (var its = new InterruptionTokenSource()) { PdfOptions CADf = new PdfOptions(); CADf.VectorRasterizationOptions = rasterizationOptions; CADf.InterruptionToken = its.Token; var exportTask = Task.Factory.StartNew(() => { cadDrawing.Save(OutputDir + "PutTimeoutOnSave_out.pdf", CADf); }); Thread.Sleep(10000); its.Interrupt(); exportTask.Wait(); } } //ExEnd:1 Console.WriteLine("PutTimeoutOnSave executed successfully"); }
public static void Run() { //ExStart:AddTextInDWG string MyDir = RunExamples.GetDataDir_DWGDrawings(); string dwgPathToFile = MyDir + "SimpleEntites.dwg"; using (Image image = Image.Load(dwgPathToFile)) { CadText cadText = new CadText(); cadText.StyleType = "Standard"; cadText.DefaultValue = "Some custom text"; cadText.ColorId = 256; cadText.LayerName = "0"; cadText.FirstAlignment.X = 47.90; cadText.FirstAlignment.Y = 5.56; cadText.TextHeight = 0.8; cadText.ScaleX = 0.0; CadImage cadImage = (CadImage)image; cadImage.BlockEntities["*Model_Space"].AddEntity(cadText); PdfOptions pdfOptions = new PdfOptions(); CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions(); pdfOptions.VectorRasterizationOptions = cadRasterizationOptions; cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor; //cadRasterizationOptions.CenterDrawing = true; cadRasterizationOptions.PageHeight = 1600; cadRasterizationOptions.PageWidth = 1600; cadRasterizationOptions.Layouts = new string[] { "Model" }; image.Save(MyDir + "SimpleEntites_generated.pdf", pdfOptions); } //ExEnd:AddTextInDWG }
/// <summary> /// Html文字列からPdfを作成する。 /// </summary> /// <param name="html"></param> /// <param name="option"></param> /// <returns></returns> public async Task <Stream> CreatePdfStreamAsync(string htmlOrUrl, PdfOptions option, bool fromUrl = true) { var launchOption = new LaunchOptions { Headless = true }; var browser = await GetBrowser(); using (var page = await browser.NewPageAsync()) { //await page.GoToAsync("http://localhost:59375/"); //await page.GoToAsync("https://github.com/kblok/puppeteer-sharp"); //await page.SetContentAsync("<html><head></head><body>test</body></html>"); //await page.SetContentAsync(html); htmlOrUrl = fromUrl ? htmlOrUrl : "data:text/html," + htmlOrUrl; await page.GoToAsync(htmlOrUrl, new NavigationOptions() { WaitUntil = new WaitUntilNavigation[] { WaitUntilNavigation.Load, WaitUntilNavigation.Networkidle0 }, Timeout = 600000 // Timeoutを10分(初期値は30秒) }); var stream = await page.PdfStreamAsync(option); return(stream); } }
public static void Run() { //ExStart:ExportDWFToPDF // The path to the documents directory. string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string fileName = MyDir + "18-12-11 9644 - site.dwf"; using (Image image = Image.Load(fileName)) { CadRasterizationOptions dwfRasterizationOptions = new CadRasterizationOptions(); dwfRasterizationOptions.PageHeight = 500; dwfRasterizationOptions.PageWidth = 500; PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = dwfRasterizationOptions; // export string outPath = MyDir + "18-12-11 9644 - site.pdf"; image.Save(outPath, pdfOptions); //ExEnd:ExportDWFToPDF Console.WriteLine("\n3D images exported successfully to PDF.\nFile saved at " + MyDir); } }
public static object detectFormatByOpt(CommandOption opt) { Console.WriteLine("detecting format : {0}", opt.Value()); object format = null; switch (opt.Value()) { case "jpg": format = ScreenshotType.Jpeg; break; case "png": format = ScreenshotType.Png; break; case "pdf": format = new PdfOptions() { Format = PaperFormat.A4, Landscape = true }; break; default: Console.WriteLine("incorrect format! only jgp, png, pdf!"); return(null); } return(format); }
public static object detectFormatByName(CommandOption nameOpt) { string tmpName = nameOpt.Value(); int startIdx = nameOpt.Value().IndexOf(".") + 1; int subLn = nameOpt.Value().Length - startIdx; Console.WriteLine("detecting extension : {0}", nameOpt.Value()); string name = nameOpt.Value().Substring(startIdx, subLn); object format = null; switch (name) { case "jpg": format = ScreenshotType.Jpeg; break; case "png": format = ScreenshotType.Png; break; case "pdf": format = new PdfOptions() { Format = PaperFormat.A4, Landscape = true }; break; default: Console.WriteLine("incorrect format! only jgp, png, pdf!"); return(null); } return(format); }
public async Task <IActionResult> GenerateFromImage([ModelBinder(BinderType = typeof(JsonModelBinder))] PdfOptions options) { try { using var inputData = await _multipartRequestService.GetPdfInputData(); if (inputData?.File == null) { return(BadRequest()); } if (!ImageHelper.IsImage(inputData.File.ContentType)) { return(BadRequest($@"Ugyldig MIME-type ""{inputData.File.ContentType}"".")); } var pdfResult = await _pdfService.GeneratePdfFromImageAsync(inputData, options); Response.Headers.Add("Content-Type", PdfResult.ContentType); Response.Headers.Add("Content-Length", pdfResult.FileSize.ToString()); return(File(pdfResult.Data, PdfResult.ContentType, pdfResult.FileName)); } catch (Exception exception) { _logger.LogError(exception, "En feil har oppstått!"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public static void Run() { Console.WriteLine("Running example ConvertWMFToPDF"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing WMF image using (Image image = Image.Load(dataDir + "input.wmf")) { // Create an instance of EmfRasterizationOptions class and set different properties WmfRasterizationOptions emfRasterizationOptions = new WmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; emfRasterizationOptions.PageWidth = image.Width; emfRasterizationOptions.PageHeight = image.Height; // Create an instance of PdfOptions class and provide rasterization option PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; // Call the save method, provide output path and PdfOptions to convert the WMF file to PDF and save the output image.Save(dataDir + "ConvertWMFToPDF_out.pdf", pdfOptions); } Console.WriteLine("Finished example ConvertWMFToPDF"); }
public async Task Should_return_FileAccessError_If_file_is_blocked() { var sourceFile = "TestData/test.v1.2.clear.pdf"; var targetFile = $"{sourceFile}.encrypted.pdf"; try { File.Copy(sourceFile, targetFile, true); // source is a clean file, copy it and avoid overwriting original one var request = new PdfOptions { Source = targetFile, Target = targetFile, UserPassword = "******" }; var subject = GetSubject(); var result = await subject.IsProtected(new PdfOptions { Source = targetFile }); Assert.IsFalse(result.Result); // make sure to start with an unprotected file. using (var blocker = File.Open(targetFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { result = await subject.Protect(request); Assert.IsFalse(result.Success); Assert.AreEqual("File_Access_Error", result.ErrorType); } } finally { if (File.Exists(targetFile)) { File.Delete(targetFile); } } }
public static void Run() { //ExStart:SupportForHiddenLines // The path to the documents directory. string MyDir = RunExamples.GetDataDir_DWGDrawings(); string sourceFilePath = MyDir + "Bottom_plate.dwg"; string outPath = MyDir + "Bottom_plate.pdf"; using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageHeight = cadImage.Height; rasterizationOptions.PageWidth = cadImage.Width; rasterizationOptions.Layers = new string[] { "Print", "L1_RegMark", "L2_RegMark" }; PdfOptions pdfOptions = new PdfOptions(); rasterizationOptions.Layouts = new string[] { "Model" }; pdfOptions.VectorRasterizationOptions = rasterizationOptions; cadImage.Save(outPath, pdfOptions); } Console.WriteLine("\nThe DWG file exported successfully to PDF.\nFile saved at " + MyDir); }
public async Task <byte[]> RenderUrl(string url, HtmlRendererOptions htmlOptions = null, PdfOptions pdfOptions = null) { async void OnPageRequest(object sender, RequestEventArgs args) { if (args.Request.IsNavigationRequest) { await args.Request.ContinueAsync(new Payload { Headers = htmlOptions.RequestHeaders }); } else { await args.Request.ContinueAsync(); } } await InitializeBrowser(); var page = await Browser.NewPageAsync(); if (htmlOptions?.RequestHeaders != null && htmlOptions.RequestHeaders.Count > 0) { await page.SetRequestInterceptionAsync(true); page.Request += OnPageRequest; } var pdfData = await RunInternal(url, htmlOptions, pdfOptions, page).ContinueWith(t => { if (t.IsCompletedSuccessfully) { return((object)t.Result); } return(t.Exception); }); await page.CloseAsync(); await page.DisposeAsync(); if (htmlOptions?.RequestHeaders != null && htmlOptions.RequestHeaders.Count > 0) { page.Request -= OnPageRequest; } if (pdfData is byte[] result) { return(result); } if (pdfData is Exception ex) { throw ex; } throw new InvalidOperationException("Something went terribly wrong."); }
public static void Run() { try { //ExStart:SupportForDGNV7 // The path to the documents directory. string MyDir = RunExamples.GetDataDir_ExportingDGN(); string sourceFilePath = MyDir + "Nikon_D90_Camera.dgn"; // Load an existing DGN file as CadImage. using (DgnImage dgnImage = (DgnImage)Image.Load(file)) { var options = new PdfOptions { VectorRasterizationOptions = new CadRasterizationOptions { PageWidth = 1500, PageHeight = 1500, CenterDrawing = true, AutomaticLayoutsScaling = true, BackgroundColor = Color.Black, Layouts = new string[] { "1", "2", "3", "9" }//only export 4 (1,2,3 and 9) views } }; dgnImage.Save(outFile, options); } //ExEnd:SupportForDGNV7 Console.WriteLine("\nThe DGN file exported successfully to raster image.\nFile saved at " + MyDir); } catch (Exception ex) { Console.WriteLine("Please use valid input file." + ex.Message); } }
public static void Run() { //ExStart:CroppingByRectangleEMFImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_MetaFiles(); // Create an instance of Rasterization options EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; // Create an instance of PNG options PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; Console.WriteLine("Running example CroppingByRectangleEMFImage"); // Load an existing image into an instance of EMF class using (EmfImage image = (EmfImage)Image.Load(dataDir + "Picture1.emf")) { using (FileStream outputStream = new FileStream(dataDir + "CroppingByRectangleEMFImage_out.pdf", FileMode.Create)) { // Create an instance of Rectangle class with desired size and Perform the crop operation on object of Rectangle class and Set height and width and Save the results to disk image.Crop(new Rectangle(30, 50, 100, 150)); pdfOptions.VectorRasterizationOptions.PageWidth = image.Width; pdfOptions.VectorRasterizationOptions.PageHeight = image.Height; image.Save(outputStream, pdfOptions); } } Console.WriteLine("Finished example CroppingByRectangleEMFImage"); //ExEnd:CroppingByRectangleEMFImage }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Conversion(); // Instantiate a Presentation object that represents a presentation file using (Presentation pres = new Presentation(dataDir + "ConvertToPDF.pptx")) { // Instantiate the PdfOptions class PdfOptions pdfOptions = new PdfOptions(); // Set Jpeg Quality pdfOptions.JpegQuality = 90; // Define behavior for metafiles pdfOptions.SaveMetafilesAsPng = true; // Set Text Compression level pdfOptions.TextCompression = PdfTextCompression.Flate; // Define the PDF standard pdfOptions.Compliance = PdfCompliance.Pdf15; // Save the presentation to PDF with specified options pres.Save(dataDir + "Custom_Option_Pdf_Conversion_out.pdf", SaveFormat.Pdf, pdfOptions); } }
public static void Run() { //ExStart:CustomOptionsPDFConversion // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Conversion(); // Instantiate a Presentation object that represents a presentation file using (Presentation pres = new Presentation(dataDir + "ConvertToPDF.pptx")) { // Instantiate the PdfOptions class PdfOptions pdfOptions = new PdfOptions(); // Set Jpeg Quality pdfOptions.JpegQuality = 90; // Define behavior for metafiles pdfOptions.SaveMetafilesAsPng = true; // Set Text Compression level pdfOptions.TextCompression = PdfTextCompression.Flate; // Define the PDF standard pdfOptions.Compliance = PdfCompliance.Pdf15; INotesCommentsLayoutingOptions options = pdfOptions.NotesCommentsLayouting; options.NotesPosition = NotesPositions.BottomFull; // Save the presentation to PDF with specified options pres.Save(dataDir + "Custom_Option_Pdf_Conversion_out.pdf", SaveFormat.Pdf, pdfOptions); } //ExEnd:CustomOptionsPDFConversion }
public async Task Should_return_BadPassword_If_invalid_password(string sourceFile) { var targetFile = $"{sourceFile}.encrypted.pdf"; try { File.Copy(sourceFile, targetFile, true); // source is a clean file, copy it and avoid overwriting original one var request = new PdfOptions { Source = targetFile, Target = targetFile, UserPassword = "******" // actual password is `test` }; var subject = GetSubject(); var result = await subject.Protect(request); Assert.IsFalse(result.Success); Assert.AreEqual("Bad_Password", result.ErrorType); } finally { if (File.Exists(targetFile)) { File.Delete(targetFile); } } }
public static void Run() { //ExStart:ExportPLTtoPDF // The path to the documents directory. string MyDir = RunExamples.GetDataDir_PLTDrawings(); string sourceFilePath = MyDir + "50states.plt"; using (Image cadImage = Image.Load(sourceFilePath)) { CadRasterizationOptions options = new CadRasterizationOptions { PageHeight = 1600, PageWidth = 1600, DrawType = CadDrawTypeMode.UseObjectColor, BackgroundColor = Color.White }; PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = options; cadImage.Save(MyDir + "50states.pdf", pdfOptions); } //ExEnd:ExportPLTtoPDF }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Conversion(); using (Presentation presentation = new Presentation(dataDir + "HiddingSlides.pptx")) { // Instantiate the PdfOptions class PdfOptions pdfOptions = new PdfOptions(); // Specify that the generated document should include hidden slides pdfOptions.ShowHiddenSlides = true; // Save the presentation to PDF with specified options presentation.Save(dataDir + "PDFWithHiddenSlides_out.pdf", SaveFormat.Pdf, pdfOptions); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Conversion(); // Instantiate a Presentation object that represents a presentation file using (Presentation presentation = new Presentation(dataDir + "DemoFile.pptx")) { // Instantiate the PdfOptions class PdfOptions pdfOptions = new PdfOptions(); // Setting PDF password pdfOptions.Password = "******"; // Save the presentation to password protected PDF presentation.Save(dataDir + "PasswordProtectedPDF_out.pdf", SaveFormat.Pdf, pdfOptions); } }
static void Main() { // The path to the documents directory. string dataDir = Aspose.Imaging.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); using (CadImage cadImage = (CadImage)Image.Load(dataDir + "conic_pyramid.dxf")) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageWidth = 500; rasterizationOptions.PageHeight = 500; rasterizationOptions.TypeOfEntities = TypeOfEntities.Entities3D; //rasterizationOptions.ScaleMethod = ScaleType.GrowToFit; rasterizationOptions.Layouts = new string[] { "Model" }; PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = rasterizationOptions; cadImage.Save(dataDir + "output.pdf", pdfOptions); } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Slides_Presentations_Layout(); // ExStart:SetPDFPageSize // Instantiate a Presentation object that represents a presentation file Presentation presentation = new Presentation(); // Set SlideSize.Type Property presentation.SlideSize.Type = SlideSizeType.A4Paper; // Set different properties of PDF Options PdfOptions opts = new PdfOptions(); opts.SufficientResolution = 600; // ExEnd:SetPDFPageSize // Save presentation to disk presentation.Save(dataDir + "SetPDFPageSize_out.pdf", SaveFormat.Pdf, opts); }
public static void Run() { // ExStart:ConvertDjVuToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DjVu(); // Load a DjVu image using (DjvuImage image = (DjvuImage)Image.Load(dataDir + "Sample.djvu")) { // Create an instance of PdfOptions and Initialize the metadata for Pdf document PdfOptions exportOptions = new PdfOptions(); exportOptions.PdfDocumentInfo = new PdfDocumentInfo(); // Create an instance of IntRange and initialize it with the range of DjVu pages to be exported IntRange range = new IntRange(0, 5); // Export first 5 pages // Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported and Save the result in PDF format exportOptions.MultiPageOptions = new DjvuMultiPageOptions(range); image.Save(dataDir + "ConvertDjVuToPDFFormat_out.pdf", exportOptions); } // ExEnd:ConvertDjVuToPDF }
public static void Run() { // ExStart:ConvertWMFToPDF // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing WMF image using (Image image = Image.Load(dataDir + "input.wmf")) { // Create an instance of EmfRasterizationOptions class and set different properties EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions(); emfRasterizationOptions.BackgroundColor = Color.WhiteSmoke; emfRasterizationOptions.PageWidth = image.Width; emfRasterizationOptions.PageHeight = image.Height; // Create an instance of PdfOptions class and provide rasterization option PdfOptions pdfOptions = new PdfOptions(); pdfOptions.VectorRasterizationOptions = emfRasterizationOptions; // Call the save method, provide output path and PdfOptions to convert the WMF file to PDF and save the output image.Save(dataDir + "ConvertWMFToPDF_out.pdf", pdfOptions); } // ExEnd:ConvertWMFToPDF }
public static void Run() { // ExStart:CreateEMFMetaFileImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // EmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it. EmfRecorderGraphics2D graphics = new EmfRecorderGraphics2D(new Rectangle(0, 0, 1000, 1000), new Size(1000, 1000), new Size(100, 100)); { // Create an instance of Imaging Pen class and mention its color. Pen pen = new Pen(Color.Bisque); // Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen. graphics.DrawLine(pen, 1, 1, 50, 50); // Reset the Pen color Specify the end style of the line. pen = new Pen(Color.BlueViolet, 3); pen.EndCap = LineCap.Round; // Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen and end style of line. graphics.DrawLine(pen, 15, 5, 50, 60); // Specify the end style of the line. pen.EndCap = LineCap.Square; graphics.DrawLine(pen, 5, 10, 50, 10); pen.EndCap = LineCap.Flat; // Draw a line by calling DrawLine method and passing parameters. graphics.DrawLine(pen, new Point(5, 20), new Point(50, 20)); // Create an instance of HatchBrush class to define rectanglurar brush with with different settings. HatchBrush hatchBrush = new HatchBrush { BackgroundColor = Color.AliceBlue, ForegroundColor = Color.Red, HatchStyle = HatchStyle.Cross }; // Draw a line by calling DrawLine method and passing parameters. pen = new Pen(hatchBrush, 7); graphics.DrawRectangle(pen, 50, 50, 20, 30); // Draw a line by calling DrawLine method and passing parameters with different mode. graphics.BackgroundMode = EmfBackgroundMode.OPAQUE; graphics.DrawLine(pen, 80, 50, 80, 80); // Draw a polygon by calling DrawPolygon method and passing parameters with line join setting/style. pen = new Pen(new SolidBrush(Color.Aqua), 3); pen.LineJoin = LineJoin.MiterClipped; graphics.DrawPolygon(pen, new[] { new Point(10, 20), new Point(12, 45), new Point(22, 48), new Point(48, 36), new Point(30, 55) }); // Draw a rectangle by calling DrawRectangle method. pen.LineJoin = LineJoin.Bevel; graphics.DrawRectangle(pen, 50, 10, 10, 5); pen.LineJoin = LineJoin.Round; graphics.DrawRectangle(pen, 65, 10, 10, 5); pen.LineJoin = LineJoin.Miter; graphics.DrawRectangle(pen, 80, 10, 10, 5); // Call EndRecording method to produce the final shape. EndRecording method will return the final shape as EmfImage. So create an instance of EmfImage class and initialize it with EmfImage returned by EndRecording method. using (EmfImage image = graphics.EndRecording()) { // Create an instance of PdfOptions class. PdfOptions options = new PdfOptions(); // Create an instance of EmfRasterizationOptions class and define different settings. EmfRasterizationOptions rasterizationOptions = new EmfRasterizationOptions(); rasterizationOptions.PageSize = image.Size; options.VectorRasterizationOptions = rasterizationOptions; string outPath = dataDir + "CreateEMFMetaFileImage_out.pdf"; image.Save(outPath, options); } } // ExEnd:CreateEMFMetaFileImage }