Hi

I need to take one or more files(.txt or .csv format only), convert them, one at a time and sent them to the printer in PostScript format.

The paper will be pre-printed and of A4 size. It is perforated in the middle(Portrait orientation).

For example, taking a file, A.txt, I would need to print it's content starting from the top of the A4 sheet. If the content of the .txt file is more than can fit in the top half (i.e above the perforation) it needs to be ignored. The same content needs to be printed again below the perforation.

What is the best way of doing this?

From my research of this article http://www.adobe.com/print/features/psvspdf/ , it appears that I can make use of PDF format, if PostScript isn't feasible.

If the above is true I might be able to use the code provided here http://www.codeproject.com/Articles/12266/Convert-a-Text-File-to-a-PDF-File for the conversion. But there is no way to divide the page into 2.

Another approach is to create 2 pages of A5(It's half of A4)size and then merge them to an A4 size.

I would like to do this in the fastest and cheapest way.

Thanks.

Hello,

This is my method to convert .TXT to .PDF.

            //Load
            string text = File.ReadAllText(@"E:\Sample.txt");

            //Create PDF Template
            PdfDocument document = new PdfDocument();
            PdfSection section = document.Sections.Add(); ;
            PdfPageBase page = section.Pages.Add();
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11);
            PdfStringFormat format = new PdfStringFormat();
            format.LineSpacing = 20f;
            float pageWidth = page.Canvas.ClientSize.Width;
            PdfBrush brush = PdfBrushes.Black;
            float y = 30;
            PdfStringLayouter textLayouter = new PdfStringLayouter();
            PdfStringLayoutResult result
                = textLayouter.Layout(text, font,format,new SizeF(pageWidth, 0));

            //Draw String
            foreach (LineInfo line in result.Lines)
            {
                page.Canvas.DrawString(line.Text, font, brush,0, y);
                y = y + result.LineHeight;
            }

            //Save to PDF
            document.SaveToFile("toPDF.PDF");

If you want to print two pages with A4 size, you can change the PDF template setting to meet your requirement, for example, widening spacing.

I use a .NET PDF component.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.