Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Jan 17, 2023, 3:36 PM EST
There are several libraries available in C# that allow you to create PDF documents, such as iTextSharp, PdfSharp, and MigraDoc. One of the most popular libraries for creating PDFs in C# is iTextSharp. Here is an example of how to create a two-page PDF using iTextSharp:
using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; Document document = new Document(); PdfWriter.GetInstance(document, new FileStream("two-page-pdf.pdf", FileMode.Create)); document.Open(); // Add first page document.Add(new Paragraph("This is the first page")); document.NewPage(); // Add second page document.Add(new Paragraph("This is the second page")); document.Close();kavya m144 reputationPosted Jan 17, 2023, 4:13 PM EST
Im Looking For two page view in singlepage pdf(like book spread)
Leon DRank #851 · 2.6K reputationPosted Jan 17, 2023, 10:10 PM EST
Using Spire.PDF library:
https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
using Spire.Pdf; using Spire.Pdf.Graphics; using System.Drawing; namespace CreateSections { class Program { static void Main(string[] args) { //Create a PDF document PdfDocument pdf = new PdfDocument(); PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 11f)); //Add the first section PdfSection section1 = pdf.Sections.Add(); section1.PageSettings.Size = PdfPageSize.A4; section1.PageSettings.Margins = new PdfMargins(30); //Add a page to the first section PdfPageBase page1 = section1.Pages.Add(); //Draw some text on the page page1.Canvas.DrawString("This is Page 1", font, PdfBrushes.Black, 0, 50); //Add the second section PdfSection section2 = pdf.Sections.Add(); section2.PageSettings.Size = PdfPageSize.A4; section2.PageSettings.Margins = new PdfMargins(0); //Add a page to the section section PdfPageBase page2 = section1.Pages.Add(); //Draw some text on the page page2.Canvas.DrawString("This is Page 2", font, PdfBrushes.Black, 0, 50); //Set page layout pdf.ViewerPreferences.PageLayout = PdfPageLayout.TwoPageLeft; //Save the result document pdf.SaveToFile("Output.pdf"); System.Diagnostics.Process.Start("Output.pdf"); } } }Also, you can check the below link for more functions of the library:
https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Spire.PDF-Program-Guide-Content.html
Vishal JoshiRank #377 · 6.7K reputationPosted Jan 18, 2023, 1:08 AM EST
Hello Kavya,
Please check the below code to generate tow page view PDFs.
using System.Drawing; using Spire.Pdf; namespace PDF_Booklet { class Program { static void Main(string[] args) { //Load a PDF file PdfDocument doc = new PdfDocument(); String srcPdf = @"..\read PDF.pdf"; //Create PDF booklet float width = PdfPageSize.A4.Width * 2; float height = PdfPageSize.A4.Height; doc.CreateBooklet(srcPdf, width, height, true); //Save pdf file. doc.SaveToFile("Booklet.pdf"); doc.Close(); //Launching the Pdf file. System.Diagnostics.Process.Start("Booklet.pdf"); } } }Reference Link: https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/PDF-Booklet-Create-PDF-Booklet-in-C-VB.NET.html
Thanks