Hi,
I’m trying to add watermarks to pages in a PDF using TextStamps. I want the watermarks to have a certain color and font, for that I use FormattedText options. It works well for the color but not the FontStyle. I’ve tried Helvetica, HelveticaBold and Courier, which the PDF format allegedly supports out of the box but the aspect on the final document doesn’t change, staying in what seems to be some Times-ish font.
Also worth mentioning is that our PDFs also include imported HTML with css-defined fonts (mainly Arial) and these fonts are preserved in the rendered document contrary to TextStamp fonts.
The problem has been showing up since I upgraded to Aspose.Pdf 8.2.0 but wasn’t occuring with my previous version (7.6.0).
Thanks for your help.
Guillaume
Simplified version of the code we use is in attachment
Well I got to the point where HTML rendering in a PDF seems totally undeterministic to me.
Turns out the solution I had posted there (adding to avoid text overlapping) doesn’t work as expected any more.
Basically,
header
country name
Other fieldset
will have “country name” overlapping “Other fieldset”, way lower than it should be,
header
country name
Other fieldset
once worked properly, but now there’s a huge blank space below “header”, and “country name” is clinging to “Other fieldset” 2 pixels above it, not overlapping but much too close,
header
country name
aDiv
Other fieldset
has the same problem, plus “aDiv” is rendered above “country name” instead of being under !
Hi Guillaume,
Any news ?
It’s been a while since I’ve posted the original message, we can’t release our application with misformatted PDFs. Especially considering the HTML we use displays perfectly well in a browser.
Thanks
Hi Guillaume,
GuillaumeL:Well I got to the point where HTML rendering in a PDF seems totally undeterministic to me.
Turns out the solution I had posted 481352, I am unable to notice any text overlapping issue. Can you please share the HTML which can help us in replicating this issue at our end. We apologize for this inconvenience.[C#]// will generate pdf fom html file<o:p></o:p>
string theHTMLFilename = @"C:\pdftest\sample.html.txt";
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
pdf.HtmlInfo.PageWidth = 5000;
pdf.ParseToPdf(theHTMLFilename);
//Save the pdf document
pdf.Save(@“C:\pdftest\HTMLConversion_v8.2.0.pdf”);
GuillaumeL:I’m trying to add watermarks to pages in a PDF using TextStamps. I want the watermarks to have a certain color and font, for that I use FormattedText options. It works well for the color but not the FontStyle. I’ve tried Helvetica, HelveticaBold and Courier, which the PDF format allegedly supports out of the box but the aspect on the final document doesn’t change, staying in what seems to be some Times-ish font.
//Create pdf document
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
//Set the conformance property of Pdf class to predefined value
pdf1.Conformance = Aspose.Pdf.Generator.PdfConformance.PdfA1B;
//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();
sec1.PageInfo.Margin = new Aspose.Pdf.Generator.MarginInfo { Top = 72, Bottom = 72, Left = 40, Right = 40 };
var htmlContent = " ";
var text2 = new Text(sec1, htmlContent);
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
// Add the text object containing HTML contents to PD Sections
sec1.Paragraphs.Add(text2);
var streamForPdf = new MemoryStream();
pdf1.Save(streamForPdf);
//open document
Document pdfDocument = new Document(streamForPdf);
var formattedText = new FormattedText("Sample String", System.Drawing.Color.Blue, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, 16);/* embedded */ //, textSize: options.FontSize);
//create text stamp
TextStamp textStamp = new TextStamp(formattedText);
//set whether stamp is background
textStamp.Background = true;
//set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
//add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);
//save output document
pdfDocument.Save("c:/pdftest/TextStamp_output.pdf");
streamForPdf.Close();