public static void Convert() { PdfUnitConverter converter = new PdfUnitConverter(); WordDocument wordDoc = new WordDocument(); var section = wordDoc.AddSection(); section.PageSetup.PageSize = new SizeF(converter.ConvertUnits(132, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point), converter.ConvertUnits(150, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point)); var paragraph = section.AddParagraph(); IWTextBox textBox = paragraph.AppendTextBox(converter.ConvertUnits(50, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point), converter.ConvertUnits(50, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point)); //Sets up some generic formatting such as making the box transparent and without a border textBox.TextBoxFormat.NoLine = true; textBox.TextBoxFormat.FillColor = Color.Red; textBox.TextBoxFormat.AutoFit = false; textBox.TextBoxFormat.InternalMargin.Bottom = 0; textBox.TextBoxFormat.InternalMargin.Top = 0; textBox.TextBoxFormat.InternalMargin.Left = 0; textBox.TextBoxFormat.InternalMargin.Right = 0; //add a paragraph var textBoxParagraph = textBox.TextBoxBody.AddParagraph(); textBoxParagraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right; textBoxParagraph.ParagraphFormat.AfterSpacing = 0; var text = textBoxParagraph.AppendText("test\ntest2\ntest3"); text.CharacterFormat.TextColor = Color.Transparent; var wordDocConverter = new DocIORenderer { Settings = { EmbedFonts = true, EmbedCompleteFonts = true } }; PdfDocument pdfDocument = null; pdfDocument = wordDocConverter.ConvertToPDF(wordDoc); using (MemoryStream stream = new MemoryStream()) { //Saves the document to stream wordDoc.Save(stream, Syncfusion.DocIO.FormatType.Docx); stream.Seek(0, SeekOrigin.Begin); using (FileStream fs = new FileStream("D:\\" + Guid.NewGuid().ToString() + "outputWordDoc.docx", FileMode.OpenOrCreate)) { stream.CopyTo(fs); fs.Flush(); } } wordDocConverter.Dispose(); wordDoc.Dispose(); using (MemoryStream stream = new MemoryStream()) { //Saves the document to stream pdfDocument.Save(stream); stream.Seek(0, SeekOrigin.Begin); using (FileStream fs = new FileStream("D:\\" + Guid.NewGuid().ToString() + "outputpdfConverted.pdf", FileMode.OpenOrCreate)) { stream.CopyTo(fs); fs.Flush(); } pdfDocument.Close(); pdfDocument.Dispose(); } }
|
Issue |
Solution |
|
In PDF, text will render invisible. |
textBox.TextBoxFormat.FillColor = Color.Red;
text.CharacterFormat.TextColor = Color.White; |
|
In PDF, text will render black. |
textBox.TextBoxFormat.FillColor = Color.Transparent;
text.CharacterFormat.TextColor = Color.White; |
|
//Appends new textbox to the paragraph IWTextBox textbox = paragraph.AppendTextBox(150, 75); //Sets fill color for textbox textbox.TextBoxFormat.FillColor = Color.Empty; //Sets a value indicates whether the textbox has no line around its shape. textbox.TextBoxFormat.NoLine = true; //Adds new text to the textbox body IWParagraph textboxParagraph = textbox.TextBoxBody.AddParagraph(); textboxParagraph.AppendText("Text inside text box"); textboxParagraph = textbox.TextBoxBody.AddParagraph(); //Adds new picture to textbox body IWPicture picture = textboxParagraph.AppendPicture(Image.FromFile(@"Syncfusion.png")); picture.Height = 40; picture.Width = 150; //Sets text wrapping style as behind for picture picture.TextWrappingStyle = TextWrappingStyle.Behind; |