Insert a line break into the 2nd paragraph. (section.Blocks as Paragraph).ParagraphFormat.Alignment = HorizontalAlignment.Center ĭb.CharacterFormat.FontColor = Color.Blue ĭb.Write("This is a first line in 2nd paragraph.") Add 2nd line to the 1st paragraph, create 2nd paragraph. Add a line break into the 1st paragraph.ĭb.InsertSpecialCharacter(SpecialCharacterType.LineBreak) Add 1st paragraph with formatted text.ĭb.CharacterFormat.FontColor = Color.Orange ĭb.Write("This is a first line in 1st paragraph!") String docPath = Create a new document and DocumentBuilder.ĭocumentBuilder db = new DocumentBuilder(dc) public static void CreatePdfUsingDocumentBuilder() Way 1: Creating a new document using DocumentBuilderĭocumentBuilder is a powerful class that is associated with a DocumentCore and allows dynamic document building from scratch or the addition of new elements to an existing document.Įverything that is possible with DocumentBuilder is also possible when using the classes of the DOM (Document Object Model) directly, but usually require more lines of code than using DocumentBuilder. Using DOM (Document Object Model) directly. Use any of them, which is more clear to you: Just a little application to do this, without any limitation.Here we'll you show two ways to create the same PDF document from a scratch. No more using online services to convert images to PDF. Erase filesToProcessĭon't forget to rename all controls on your form to fit the above code. GR.DrawImage(xImg, 0, 0, page.Width, page.Height)īwMakePdf.ReportProgress((i / fileCount) * 100) Page.Height = xImg.PixelHeight * 72 / xImg.HorizontalResolution Page.Width = xImg.PixelWidth * 72 / xImg.HorizontalResolution ' Resize page Width and Height to fit image size. If bwMakePdf.CancellationPending Then Exit For End If ' Create new PDF page. Dim fileCount As Integer = filesToProcess.Length - 1 ' Add PDF pages. Dim filesToProcess = Array.FindAll( Of String)(allFiles, findMatch) png") Or _Įnd Function ' Find entire array. ' PDFSharp only supports PNG, BMP, JPG, and GIF. Dim findMatch = Function(filePath As String) ' Function to find compatible file types. Dim allFiles = Directory.GetFiles(info.InputDirectory, " *.*", SearchOption.TopDirectoryOnly) ![]() ' Find all files on source directory (sub-directories not included). Dim info As WorkerParameters = DirectCast(e.Argument, WorkerParameters) I put this code in bwMakePDF_DoWork event handler. ![]() You can add it from Nuget Package or download it from official website. Second, add reference to PDFSharp library. ![]() NET Framework 2.0 for maximum compatibility.Īlso, I added SaveFileDialog, FolderBrowseDialog, and BackgroundWorker. On the For.Next loop, add new PDF page with image as the content.įirst, you must create new Windows Forms Application.Move supported image file paths to new array. ![]()
0 Comments
Leave a Reply. |