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.

Thu May 28, 2020 5:28 am

Hi, I want to convert some text with HTML inputs tag to a rectangle, like a real input. So, I replace the input tag with a custom tag whose have the exact width of the rectangle, and I paint a rectangle in it. After that, I fill it with a blank rectangle. That's works great, but I have a problem, sometimes, PDFLayouter breaks my custom tag and don't work properly. Is there any way to avoid word-breaking?

Thank you a lot.

davdomvaz
 
Posts: 2
Joined: Thu May 28, 2020 5:21 am

Thu May 28, 2020 7:43 am

Hello,

Thanks for your inquiry.
To help us investigate your issue more accurately and quickly, please provide the text string you used, your test code as well as your output file. You could upload them here or send them to us([email protected]) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu May 28, 2020 8:09 am

Hi, thank you for your quickly response.

the text I want to fit is:
"Al cambiar de rama <<<<<<<<1>>>>>>>> y hacer el merge a través de fetch he <<<<<<<<1>>>>>>>> introducido fallos en el proyecto. Paco Ramirez me ha ayudado a corregirlos y ya está disponible el proyecto correctamente. Voy a probar el compo Buenos días:"
Where "<<<<<<<<1>>>>>>>>" is the custom tag I'm talking about.

And the fragment code I used:

"
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
format.LineSpacing = 10f;
PdfStringLayouter stringLayout = new PdfStringLayouter();
PdfStringLayoutResult result = stringLayout.Layout(text, font2, format, new SizeF(document.Pages[pageCount - 1].GetClientSize().Width / (1.22f), 0));
PointF position = new PointF(0, Y);

foreach (LineInfo line in result.Lines)
{
document.Pages[pageCount - 1].Canvas.DrawString(line.Text, fontBodyRegular, PdfBrushes.Black, position, format);
position.Y = position.Y + result.LineHeight;

if ((position.Y + result.LineHeight + format.LineSpacing * 10) > document.Pages[pageCount - 1].ActualSize.Height)
{
pageCount = CreateHeader(document, formula, material, true);
Y = 60f;

position = new PointF(0, Y);
}
}
"

I tried to set the attribute WordWrap of PdfStringFormat at true, but still not working.

If you need more information, don't worry in telling me.

Thanks.

davdomvaz
 
Posts: 2
Joined: Thu May 28, 2020 5:21 am

Thu May 28, 2020 11:25 am

Hello,

Thanks you for providing more information.
I simulated the complete code and tested with the latest Spire.PDF Pack(Hot Fix) Version:6.5.15 but did not encounter the word-breaking issue you mentioned. Below is the code I used and I also attached my output file.
In order to help us better reproduce your issue, please provide us with your input file, your full code or a sample runnable project. And please also provide your expected output help us better understand the effect you want to achieve. You could send them to us([email protected]) via email. Thanks in advance.
Code: Select all
    PdfDocument document = new PdfDocument();
    document.LoadFromFile("test.pdf");
    int pageCount = document.Pages.Count;
    string text = "Al cambiar de rama <<<<<<<<1>>>>>>>> y hacer el merge a través de fetch he <<<<<<<<1>>>>>>>> introducido fallos en el proyecto. Paco Ramirez me ha ayudado a corregirlos y ya está disponible el proyecto correctamente. Voy a probar el compo Buenos días:";
    PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
    format.LineSpacing = 10f;
    float Y = 150;
    PdfStringLayouter stringLayout = new PdfStringLayouter();
    PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arail", 12, FontStyle.Regular));
    PdfTrueTypeFont fontBodyRegular = new PdfTrueTypeFont(new Font("Arail", 12, FontStyle.Regular));

    PdfStringLayoutResult result = stringLayout.Layout(text, font2, format, new SizeF(document.Pages[pageCount - 1].GetClientSize().Width / (1.22f), 0));
    PointF position = new PointF(0, Y);
    foreach (LineInfo line in result.Lines)
    {
        document.Pages[pageCount - 1].Canvas.DrawString(line.Text, fontBodyRegular, PdfBrushes.Black, position, format);
        position.Y = position.Y + result.LineHeight;
        if ((position.Y + result.LineHeight + format.LineSpacing * 10) > document.Pages[pageCount - 1].ActualSize.Height)
        {
            Y = 60f;
            position = new PointF(0, Y);
        }
    }
    document.SaveToFile("out.pdf", FileFormat.PDF);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF