Search code examples
c#.netasposeaspose.pdf

How to create blank pdf from scratch using aspose.pdf for .net?


I want to know that which class should I use for creating blank pdf for writing my content into it through c# code but in the documentation of aspose.pdf they are suggesting to use Aspose.Pdf.Generator.Pdf class but that specific namespace is obsolete from Aspose.Pdf api.


Solution

  • @Shashank,

    Aspose.Pdf.Genertor is obsolete but Aspose.Pdf namespace is new Document Object Model which provides the capabilities to create as well as manipulate existing PDF files. So as per your requirements, you can use this namespace to create PDF files from scratch. Note that all the features of legacy Aspose.Pdf.Generator are present in new DOM approach.

    [c#]

    // create Document instance
    Aspose.Pdf.Document mypdf = new Aspose.Pdf.Document();
    // add page to pages collection of Document instance
    mypdf.Pages.Add();
    // create TextFragment instance
    Aspose.Pdf.Text.TextFragment fragment = new TextFragment("Hello World....");
    // add fragment to first page of document
    mypdf.Pages[1].Paragraphs.Add(fragment);
    // save PDF document
    mypdf.Save("c:/pdftest/PdfFile.pdf");