Exemple #1
0
        public unsafe static SKDocument CreatePdf(SKWStream stream, SKDocumentPdfMetadata metadata, float dpi = DefaultRasterDpi)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (var title = SKString.Create(metadata.Title))
                using (var author = SKString.Create(metadata.Author))
                    using (var subject = SKString.Create(metadata.Subject))
                        using (var keywords = SKString.Create(metadata.Keywords))
                            using (var creator = SKString.Create(metadata.Creator))
                                using (var producer = SKString.Create(metadata.Producer)) {
                                    var cmetadata = new SKDocumentPdfMetadataInternal {
                                        Title    = title?.Handle ?? IntPtr.Zero,
                                        Author   = author?.Handle ?? IntPtr.Zero,
                                        Subject  = subject?.Handle ?? IntPtr.Zero,
                                        Keywords = keywords?.Handle ?? IntPtr.Zero,
                                        Creator  = creator?.Handle ?? IntPtr.Zero,
                                        Producer = producer?.Handle ?? IntPtr.Zero
                                    };
                                    if (metadata.Creation != null)
                                    {
                                        var creation = SKTimeDateTimeInternal.Create(metadata.Creation.Value);
                                        cmetadata.Creation = &creation;
                                    }
                                    if (metadata.Modified != null)
                                    {
                                        var modified = SKTimeDateTimeInternal.Create(metadata.Modified.Value);
                                        cmetadata.Modified = &modified;
                                    }

                                    return(GetObject <SKDocument> (SkiaApi.sk_document_create_pdf_from_stream_with_metadata(stream.Handle, dpi, ref cmetadata)));
                                }
        }
Exemple #2
0
        public static SKDocument CreatePdf(SKWStream stream, SKDocumentPdfMetadata metadata)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            using (var title = SKString.Create(metadata.Title))
                using (var author = SKString.Create(metadata.Author))
                    using (var subject = SKString.Create(metadata.Subject))
                        using (var keywords = SKString.Create(metadata.Keywords))
                            using (var creator = SKString.Create(metadata.Creator))
                                using (var producer = SKString.Create(metadata.Producer)) {
                                    var cmetadata = new SKDocumentPdfMetadataInternal {
                                        fTitle           = title?.Handle ?? IntPtr.Zero,
                                        fAuthor          = author?.Handle ?? IntPtr.Zero,
                                        fSubject         = subject?.Handle ?? IntPtr.Zero,
                                        fKeywords        = keywords?.Handle ?? IntPtr.Zero,
                                        fCreator         = creator?.Handle ?? IntPtr.Zero,
                                        fProducer        = producer?.Handle ?? IntPtr.Zero,
                                        fRasterDPI       = metadata.RasterDpi,
                                        fPDFA            = metadata.PdfA ? (byte)1 : (byte)0,
                                        fEncodingQuality = metadata.EncodingQuality,
                                    };

                                    SKTimeDateTimeInternal creation;
                                    if (metadata.Creation != null)
                                    {
                                        creation            = SKTimeDateTimeInternal.Create(metadata.Creation.Value);
                                        cmetadata.fCreation = &creation;
                                    }
                                    SKTimeDateTimeInternal modified;
                                    if (metadata.Modified != null)
                                    {
                                        modified            = SKTimeDateTimeInternal.Create(metadata.Modified.Value);
                                        cmetadata.fModified = &modified;
                                    }

                                    return(Referenced(GetObject <SKDocument> (SkiaApi.sk_document_create_pdf_from_stream_with_metadata(stream.Handle, &cmetadata)), stream));
                                }
        }