How to adjust font size in syncfusion html to pdf - pdf

I am able to convert HTML to PDF using syncfusion.
The issue I have is it doesn't obey the font sizes
var htmlText = "<html><head><style>body{font-size:50px;}</style></head><body>Hello</body></html>";
var convertedHtmlDocument = ConvertFromHtml(htmlText);
var ms = new MemoryStream();
var fpath = AppDomain.CurrentDomain.BaseDirectory + "myfile.pdf";
SaveToFile(convertedHtmlDocument, fpath);
ms.Dispose();
It doesn't matter if I make the font size in the CSS 50 or 5, the font comes out the same size.
I also tried (same issue):
var htmlText = "<html><head><style>.myclass {font-size:50px;}</style></head><body><div class="myapp">Hello</div></body></html>";
Exporting the above 2 to an .html document behaves as the syntax suggests.
If I change my CSS to use table then it works, but I want to have a single font size for the document, not just the table
var htmlText = "<html><head><style>table{font-size:50px;}</style></head><body>Hello</body></html>"; //this works
What am I doing wrong?

We have checked the reported issue with different font size but it is working properly on our end. We have attached the sample and output for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WPF1621828031
Output: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Output259867595
If still you have facing the issue, we request you share the modified code sample, input html text and product version ,screenshot of the issue to check this on our end. It will be helpful for us to analyse and assist you further on this.

Related

After content stream recreation (using PDFbox) getting error in axesPDF (insert spaces)?

when I am recreating a pdf after some changes , if I use the output pdf in axesPDF to fix spaces issue I am getting "ERROR". The only difference I observed my input pdf have Array of tokens but my recreated pdf has Dictionary of elements. As shown in below. Does that cause the problem? How can I recreate similar structure? (Left one is input pdf right one output pdf after editing)
Input pdf
output pdf with changes
The code I am using to save the pdf is
PDStream newContents = new PDStream(document);
OutputStream out = newContents.createOutputStream(COSName.FLATE_DECODE);
ContentStreamWriter writer = new ContentStreamWriter(out);
writer.writeTokens(tokens);
out.close();
document.getPage(pg_ind).setContents(newContents);
newPDF.addPage(document.getPage(pg_ind));
newPDF.save()
Please help me on this. Thanks in advance.
Updating question along with error.
Another Input file
The error is
The button I used.
I am wondering this time even the content stream is in COSDictionary format it's giving error. Something else causing this.

Add text to existing PDF using Python and PDFTron

I’m trying to add text dynamically to an existing PDF with a font available in the system using pdfnetpython3 9.1.0 from the PDFTron SDK. I’m using the following Python code:
texts = ["test1", "test2"]
ewriter = ElementWriter()
ebuilder = ElementBuilder()
# not shown here: create PDFDoc object from PDF in disk
page = pdf_doc.GetPage(3)
ewriter.Begin(page)
element = ebuilder.CreateTextBegin(Font.Create(pdf_doc.GetSDFDoc(), "Inter", ""), 11)
ewriter.WriteElement(element)
for i, text in enumerate(texts):
element = ebuilder.CreateTextRun(text)
element.SetTextMatrix(1, 0, 0, 1, 0, 20*i)
ewriter.WriteElement(element)
i += 1
element = ebuilder.CreateTextEnd()
ewriter.WriteElement(element)
ewriter.End() # save changes to the current page
However, the text shows up in Japanese characters in the saved PDF. Am I loading the font incorrectly by passing its name and an empty string as char_set ? I’ve followed the sample that loads the Helvetica font in https://www.pdftron.com/documentation/samples/py/UnicodeWriteTest .
I have tried to call PDFNet.AddFontSubst() with the Inter font file path as parameter before rendering the strings, but I got the same result.
I’m only able to load the font correctly if I provide a Font.StandardType1Font (e.g. Font.e_times_roman) instead of a font name to Font.Create() (this links to the .NET sdk, but .NET and Python SDK uses the same classes and methods names).

PDFBox: Fill out a PDF with adding repeatively a one-page template containing a form

Following SO question Java pdfBox: Fill out pdf form, append it to pddocument, and repeat I had trouble appending a cloned page to a new PDF.
Code from this page seemed really interesting, but didn't work for me.
Actually, the answer doesn't work because this is the same PDField you always modify and add to the list. So the next time you call 'getField' with initial name, it won't find it and you get an NPE. I tried with the same pdfbox version used (1.8.12) in the nice github project, but can't understand how he gets this working.
I had the same issue today trying to append a form on pages with different values in it. I was wondering if the solution was not to duplicate field, but can't succeed to do it properly. I always end with a PDF containing same values for each form.
(I provided a link to the template document for Mkl, but now I removed it because it doesn't belong to me)
Edit: Following Mkl's advices, I figured it out what I was missing, but performances are really bad with duplicating every pages. File size isn't satisfying. Maybe there's a way to optimize this, reusing similar parts in the PDF.
Finally I got it working without reloading the template each time. So the resulting file is as I wanted: not too big (4Mb for 164 pages).
I think I did 2 mistakes before: one on page creation, and probably one on field duplication.
So here is the working code, if someone happens to be stuck on the same problem.
Form creation:
PDAcroForm finalForm = new PDAcroForm(finalDoc, new COSDictionary());
finalForm.setDefaultResources(originForm.getDefaultResources())
Page creation:
PDPage clonedPage = templateDocument.getPage(0);
COSDictionary clonedDict = new COSDictionary(clonedPage.getCOSObject());
clonedDict.removeItem(COSName.ANNOTS);
clonedPage = new PDPage(clonedDict);
finalDoc.addPage(clonedPage);
Field duplication: (rename field to become unique and set value)
PDTextField field = (PDTextField) originForm.getField(fieldName);
PDPage page = finalDoc.getPages().get(nPage);
PDTextField clonedField = new PDTextField(finalForm);
List<PDAnnotationWidget> widgetList = new ArrayList<>();
for (PDAnnotationWidget paw : field.getWidgets()) {
PDAnnotationWidget newWidget = new PDAnnotationWidget();
newWidget.getCOSObject().setString(COSName.DA, paw.getCOSObject().getString(COSName.DA));
newWidget.setRectangle(paw.getRectangle());
widgetList.add(newWidget);
}
clonedField.setQ(field.getQ()); // To get text centered
clonedField.setWidgets(widgetList);
clonedField.setValue(value);
clonedField.setPartialName(fieldName + cnt++);
fields.add(clonedField);
page.getAnnotations().addAll(clonedField.getWidgets());
And at the end of the process:
finalDoc.getDocumentCatalog().setAcroForm(finalForm);
finalForm.setFields(fields);
finalForm.flatten();

How to embed font into pdf/a using iText7

I'm trying to see how to embed fonts into my pdf/a.
I found a lot of answer but using iTextSharp.
In my cas I use iText7 and all I tried gave me the error:
"All the fonts must be embedded..."
I have a ttf file for my font but I didn't find a way to embed it into my pdf to use it...
Could someone help me?
Thanks in advance
kor6k
As documented in the tutorial and as indicated by the error you mention ("All the fonts must be embedded"), you need to embed the fonts.
You are probably not defining a font, in which case the standard Type 1 font Helvetica will be used. These standard Type 1 fonts are never embedded, hence you need to pick another font.
The example from the tutorial uses the free font FreeSans:
public const String FONT = "resources/font/FreeSans.ttf";
The font object is defined like this:
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
This font is used in a Paragraph like this:
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("Font is embedded"));
document.Add(p);
This is the C# version. If you need the Java version, take a look at the Java version of the tutorial:
public static final String FONT = "src/main/resources/font/FreeSans.ttf";
PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.setFont(font);
p.add(new Text("Font is embedded"));
document.add(p);
If you already use this approach, and you still get the error, you probably have some content somewhere for which you didn't define a font that is embedded.

Docx4J: Vertical text frame not exported to PDF

I'm using Docx4J to make an invoice model.
In the left-side of the page, it's usual to show a legal sentence as: Registered company in ... Book ... Page ...
I have inserted this in my template with a Word text frame.
Well, my issue is: when exporting to .docx, this legal text is shown perfect, but when exporting to .pdf, it's shown as an horizontal table under the other data.
The code to export to PDF is:
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(foDumpFile);
foSettings.setWmlPackage(template);
fos = new FileOutputStream(new File("/C:/mypath/prueba_OUT.pdf"));
Docx4J.toFO(foSettings, fos, Docx4J.FLAG_EXPORT_PREFER_XSL);
Any help would be very appreciated.
Thanks.
You'd need to extend the PDF via FO code; see further How to correctly position a header image with docx4j?
Float left may or may not be easy; similarly the rotated text.
In general, the way to work on this is to take the FO generated by docx4j, then hand edit it to something which FOP can convert to a PDF you are happy with. If you can do that, then its a matter of modifying docx4j to generate that FO.