Resolved PDF font

HrckoV

Member
Joined
Oct 19, 2021
Messages
7
Programming Experience
10+
I'm using this code to save pdf file. With iTextSharp I'm defining a font, but on save my font in pdf is small.
What am I doing wrong?
C#:
private void savePDF(string filename)
{                     
    iTextSharp.text.Document oDoc = new iTextSharp.text.Document();

    SaveFileDialog svg = new SaveFileDialog();
    svg.InitialDirectory = ConfigurationManager.AppSettings["shopPath"];
    svg.RestoreDirectory = true;
    svg.Filter = "pdf files(*.pdf)|*.pdf";
    svg.ShowDialog();

    if (svg.FileName != String.Empty)
    {
        using (FileStream stream = new FileStream(svg.FileName, FileMode.Create))
        {
            Document pdfDoc = new Document(PageSize.A1);
            PdfWriter.GetInstance(pdfDoc, stream);                 
            PdfWriter.GetInstance(pdfDoc, stream);
            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 24, iTextSharp.text.Font.BOLD);

            pdfDoc.Open();

            pdfDoc.Add(new Paragraph(new Chunk(stream.ToString(), font)));
            pdfDoc.Close();
            stream.Close();
        }

        oDoc.Close();
    }
}
 
Last edited by a moderator:
A1 is a large paper size (around 8 A4 sheets), text can appear small depending on view/zoom.
 
With iTextSharp I'm defining a font, but on save my font in pdf is small.
Did you actually print your PDF? Did you print it as full size, or to fit the paper available on the printer? When you printed it out full size and measured the height of the a capital letter T, did you get about 1/3 of an inch, or about 8.5 mm?
 
Why did you choose A1? Did you copy that code from elsewhere without considering the paper size? Wouldn't you want the page size to be A4, i.e. what most people would consider the normal size of a document page? An A1 page would have to be shrunk considerably to fit on even a large monitor, so your text would be shrunk accordingly. If you are determined to stick with A1, make sure that the document is at 100% magnification/zoom when you preview it.
 
And what was the scaling value in the PDF viewer while you were viewing it? Also, were you using a high DPI display? Did you configure your OS to let it know that you are using a high DPI display?

Anyway, I think that @JohnH hit the nail on the head regarding the A1 sheet. Consider that 24 point font is about 8.5mm tall. Put that on an A1 sheet that is 594x841mm, then yes the font will look tiny on the sheet.
 
I changed the size to A4 and increase font to 48, but it is still the same size. Seems like the size is not changing. My preview is on 100%.
 
Are you using the latest iText 7? I'm guessing not, because I don't think that that uses the name iTextSharp any more. It might be worth looking into that. I did read somewhere that setting a standard font size is easier in the newer version but I have no idea about the details.
 
Back
Top Bottom