Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jan 08, 2024 6:44 am

I was using iText jar class BaseFont class like BaseFont.createFont( BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

Now I want to use Spire PDF class PdfTrueTypeFont(java.awt.Font) to create a font for stamping. I want to use the encoding as CP1252 and also the NOT_EMBEDDED property but not able to find out how to use it with awt Font class or PdfTrueTypeFont class. please let me know.

bhavnahingar
 
Posts: 2
Joined: Mon Jan 08, 2024 6:37 am

Mon Jan 08, 2024 9:56 am

Hi,

Thank you for your inquiry.
Sorry, our product currently doesn’t support the use of awt Font or PdfTrueTypeFont classes together. We deeply apologize for any inconvenience caused.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Mon Jan 08, 2024 10:33 am

If spire pdf does not support PdfTrueTypeFont and awt.font together, how do i add a date at the end of the page if i want to add.

Please let me know

I referred below link

<ice-blue website>/api_documents/5d4cd5345ea595-13146674/res/html/com/spire/pdf/graphics/PdfTrueTypeFont.html

bhavnahingar
 
Posts: 2
Joined: Mon Jan 08, 2024 6:37 am

Tue Jan 09, 2024 2:56 am

Hi,

Thank you for your feedback.
Our product supports adding date at the end of the page, I put the complete code below for your reference:
Code: Select all
    // Create a new PDF document
    PdfDocument doc = new PdfDocument();

    // Set the size of the pages to A4
    doc.PageSettings.Size = PdfPageSize.A4;

    // Set the margins of the pages to 0
    doc.PageSettings.Margins = new PdfMargins(0);

    // Create a new PdfMargins object with custom values for top, bottom, left, and right margins
    PdfMargins margins = new PdfMargins(40, 60, 40, 60);

    // Set the bottom template of the document to the created footer template
    doc.Template.Bottom = CreateFooterTemplate(doc, margins);

    // Set the left template of the document to a new PdfPageTemplateElement with the specified margins and page size height
    doc.Template.Left = new PdfPageTemplateElement(margins.Left, doc.PageSettings.Size.Height);

    // Set the right template of the document to a new PdfPageTemplateElement with the specified margins and page size height
    doc.Template.Right = new PdfPageTemplateElement(margins.Right, doc.PageSettings.Size.Height);

    // Add a new page to the document
    PdfPageBase page1 = doc.Pages.Add();

    // Add another new page to the document
    PdfPageBase page2 = doc.Pages.Add();

    // Create a new PdfTrueTypeFont object with the specified font name, size, and style
    PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("华文楷体", 15f, FontStyle.Bold), true);
    // Save the document to a file named "HeaderAndFooter7.pdf"
    doc.SaveToFile(@"..\HeaderAndFooter7.pdf");
}
// Define a static method to create a footer template for the document
static PdfPageTemplateElement CreateFooterTemplate(PdfDocument doc, PdfMargins margins)
{
    // Get the size of the page settings
    SizeF pageSize = doc.PageSettings.Size;
   
    // Create a new PdfPageTemplateElement with the specified width and bottom margins
    PdfPageTemplateElement footerSpace = new PdfPageTemplateElement(pageSize.Width, margins.Bottom);
   
    // Set the foreground color of the footer space to false
    footerSpace.Foreground = false;
   
    // Initialize the x and y coordinates for drawing the line
    float x = margins.Left;
    float y = 0;
   
    // Create a new PdfPen with a gray brush and a thickness of 0.5
    PdfPen pen = new PdfPen(PdfBrushes.Gray, 0.5f);
 
    // Draw a line from the top-left corner to the bottom-right corner of the footer space
    footerSpace.Graphics.DrawLine(pen, x, y, pageSize.Width - x, y);
   
    // Increment the y coordinate by 5
    y = y + 5;
   
    // Create a new PdfTrueTypeFont object with the specified font name, size, and style
    PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("黑体", 10f, FontStyle.Bold), true);
   
    // Create a new PdfStringFormat object with the specified text alignment
    PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
   
    // Get the current date and time
    DateTime s1 = DateTime.Now;
   
    // Create a string containing the date and time information
    String footerText = "日期:" + s1;
   
    // Draw the footer text on the footer space using the specified font, brush, x and y coordinates, and format
    footerSpace.Graphics.DrawString(footerText, font, PdfBrushes.Black, x, y, format);
   
    // Return the created footer space
    return footerSpace;
}

If the issue still exists, please offer your file to help us do further investigation, you can attach here or send it to us via email ([email protected] ). Thank you in advance.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.PDF