public static void AddImageInLine() { PdfDocument document = new PdfDocument(); //Create document level builder using (PdfDocumentBuilder builder = new PdfDocumentBuilder(document)) { builder.InsertParagraph(); //You can insert same image to different position in page, or insert different images to respective position using (Stream sampleImage = File.OpenRead("sample.jpg")) { builder.InsertImageInline(sampleImage, new Size(40, 40)); builder.InsertText(", second one:"); builder.InsertImageInline(sampleImage, new Size(100, 100)); builder.InsertText(" and third one:"); builder.InsertImageInline(sampleImage, new Size(100, 60)); builder.InsertText(" the end."); } } using (FileStream fs = File.OpenWrite("InsertImageInLine.pdf")) { PdfFile pdfFile = new PdfFile(); pdfFile.Export(document, fs); } }
public static void AddText2() { //This example is using document level builder(flow-like), if the text inserted is out of one page, //the builder will insert the left text on a second page automatically PdfDocument document = new PdfDocument(); //Create document level builder using (PdfDocumentBuilder builder = new PdfDocumentBuilder(document)) { //Set page size and margins builder.SectionState.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4); builder.SectionState.PageMargins = new Padding(20); //Set text alignment builder.ParagraphState.HorizontalAlignment = Editing.Flow.HorizontalAlignment.Center; //Set font style builder.CharacterState.SetFont(new FontFamily("LegacySansEFOP-Book")); builder.CharacterState.FontSize = 40; builder.InsertParagraph(); builder.InsertText("Document Title"); builder.InsertLineBreak(); //Add several paragraphs to page builder.ParagraphState.HorizontalAlignment = Editing.Flow.HorizontalAlignment.Left; builder.CharacterState.FontSize = 20; for (int i = 0; i < 20; i++) { builder.InsertParagraph(); string text = ""; for (int j = 1; j < 11; j++) { text += "This is sentence " + j.ToString() + ". "; } builder.InsertText(text); builder.InsertLineBreak(); } } using (FileStream fs = File.Create("InsertText2.pdf")) { PdfFile pdfFile = new PdfFile(); pdfFile.Export(document, fs); } }