Вопрос

How can I generate a pdf in winRT apps? I'm using iTextSharp to generate pdfs in windows store apps, but winRT does not have filestream, filemode or filedirectory. help

Here is my code:

iTextSharp.text.pdf.PdfWriter writer = 
    iTextSharp.text.pdf.PdfWriter.GetInstance(
        doc, new System.IO.FileStream(System.IO.Directory.GetCurrentDirectory() +
                                      "\\ScienceReport.pdf", System.IO.FileMode.Create
        )
    );
Это было полезно?

Решение

I can generate a PDF file in winrt

        string path = @"ExportPDF.pdf";
        var storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

        // Create empty PDF file.
        var file = await storageFolder.CreateFileAsync(path, CreationCollisionOption.ReplaceExisting);
        if (file != null)
        {
            await FileIO.WriteTextAsync(file, string.Empty);
        }

        // Open to PDF file for read/write.
        StorageFile sampleFile = await storageFolder.GetFileAsync(path);
        var stream = await sampleFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

        // Create an instance of the document class which represents the PDF document itself.
        Document document = new Document(PageSize.A4, 25, 25, 30, 30);

        // Create an instance to the PDF file by creating an instance of the PDF 
        // Writer class using the document and the filestrem in the constructor.
        PdfWriter writer = PdfWriter.GetInstance(document, stream.AsStream());

        // Add meta information to the document
        document.AddAuthor("Jigs");
        document.AddCreator("Sample application");
        document.AddKeywords("PDF App");
        document.AddSubject("Document subject - Describing the steps creating a PDF document");
        document.AddTitle("The document title - PDF creation");

        // Open the document to enable you to write to the document
        document.Open();
        // Add a simple and wellknown phrase to the document in a flow layout manner
        document.Add(new Paragraph("Hello!"));

        // Close the document
        document.Close();
        // Close the writer instance
        writer.Close();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top