Hi,
Thanks for your feedback.
We have a method of replacing the font of existing text in PDF. Below is sample code.
- Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("1.pdf");
//Get the fonts used in PDF
PdfUsedFont[] fonts = doc.UsedFonts;
//Create a new font
PdfTrueTypeFont newfont = new PdfTrueTypeFont("Arial",12f,PdfFontStyle.Regular,true);
foreach (PdfUsedFont font in fonts)
{
//Replace the font with new font
font.Replace(newfont);
}
//Save the document
doc.SaveToFile("out.pdf");
But for your requirement to add html string as a paragraph on an existing pdf page, I'm sorry that there is no way to do this in our Spire.PDF product. Based on the PDF document structure specification, I'm afraid it's not feasible to implement this. For adding HTML string as a paragraph, I would recommend operating it in a Word document instead, as the Word document specification supports this feature.
I have a solution to offer you. First, use our Spire.PDF to convert your PDF file to a Word document. Then, use the Spire.Doc product to add HTML string, and finally save it to a PDF file. Here is an example code for your reference.
- Code: Select all
String outputWord = "converted.docx";
//Convert PDF to Word
using (PdfToWordConverter converter = new PdfToWordConverter("source.pdf"))
{
converter.SaveToDocx(outputWord);
}
//Add html string to Word and save to a PDF file
Document doc2 = new Document();
doc2.LoadFromFile(outputWord);
doc2.Sections[0].Paragraphs[0].AppendHTML(htmlString);
doc2.SaveToFile("result.pdf",Spire.Doc.FileFormat.PDF);
Please let us know if you have any issues.
Sincerely,
Amy
E-iceblue support team