To flatten our PDF files, we have to convert PDF Files become Postscript files, then convert Postscript files become PDF. We can use PSTOEdit which use pdf2ps and ps2pdf from ghostscript to flatten PDF files. We can use:
System("pstoedit input.pdf output.pdf -f gs:pdfwrite") then we can get the results.
Sunday, August 5, 2007
Thursday, August 2, 2007
Dynamic PDF from Dynamic HTML
To convert HTML become PDF we can use HTMLDoc which is a powerful tools to convert HTML become PDF files. But, it will convert static HTML become PDF, the question is how about to convert dynamic HTML become PDF files ? Is it possible to do ? Ya, we can do it by a very simple technique. First, we have to convert dynamic HTML become static. We can do by execute script and give output as static HTML like:
system("/usr/bin/perl yourscript.pl > output.html");
it will give output.HTML that can be converted become PDF Files.
The other question is, how about if there is parameters in your script can we do like this ?
system("/usr/bin/perl yourscript.pl?id=1 > output.html");
Of course, wa can't.
We have to convert all parameters become argv, so we can execute them. So it will be like this.
system("/usr/bin/perl yourscript.pl 1 > output.html");
Then we can get output.HTML from script then converted it become PDF Files.
system("/usr/bin/perl yourscript.pl > output.html");
it will give output.HTML that can be converted become PDF Files.
The other question is, how about if there is parameters in your script can we do like this ?
system("/usr/bin/perl yourscript.pl?id=1 > output.html");
Of course, wa can't.
We have to convert all parameters become argv, so we can execute them. So it will be like this.
system("/usr/bin/perl yourscript.pl 1 > output.html");
Then we can get output.HTML from script then converted it become PDF Files.
Wednesday, August 1, 2007
Dynamic PDF with PHP
We can make dynamic PDF using fpdf which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. But if we just using this, it will be difficult if we want to make a 'nice' pdf document with a template that we have provided before and we just replace text in template. We can make it by using PDF template then replace the signed text in PDF template. How ever it has a lack, how about the text is more than provided space in template PDF ? It will be some trouble.
We can use another way, design your template in HTML, process template content; may be replace text in content, build another table, etc, then convert it become PDF files. We can use html2fpdf to convert. It will be easier than create template in PDF files.
We can use another way, design your template in HTML, process template content; may be replace text in content, build another table, etc, then convert it become PDF files. We can use html2fpdf to convert. It will be easier than create template in PDF files.
Printing Form Controls in .NET
I got a project that ordered me to print out a form in .NET. There is a simple way to print out form. We can use DrawToBitmap methode in each .NET controls to converts forms become bitmap, then move it to printer graphics objects.
To print out, we need three other controls: PageSetupDialog, PrintDocument, and PrintPreviewDialog.
We can handle PrintPage events in PrintDocument to draw form and controls to printer graphics object:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim r As Rectangle = New Rectangle(e.MarginBounds.Location,Me.DisplayRectangle.Size)
e.Graphics.Clip = New Region(e.MarginBounds)
Dim a As New Bitmap(r.Width, r.Height, e.Graphics)
'Draw to bitmap
Me.DrawToBitmap(a, r)
'Draw bitmap to printer graphics object
e.Graphics.DrawImage(a, r)
e.Graphics.ResetClip()
a = Nothing
'continue print other page or not
e.HasMorePages = False
End Sub
Then print function:
Private Sub Print()
'Seting Page Setup
PageSetupDialog1.PageSettings.Margins.Top = 0 PageSetupDialog1.PageSettings.Margins.Bottom = 0
PageSetupDialog1.PageSettings.Margins.Left = 0
PageSetupDialog1.PageSettings.Margins.Right = 0
Dim pdOld As Printing.PrintDocument = Me.PrintPreviewDialog1.Document
Me.PrintPreviewDialog1.Document = Me.PrintDocument1
Me.PrintPreviewDialog1.ShowDialog()
Me.PrintPreviewDialog1.Document = pdOld
End Sub
To print out, we need three other controls: PageSetupDialog, PrintDocument, and PrintPreviewDialog.
We can handle PrintPage events in PrintDocument to draw form and controls to printer graphics object:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim r As Rectangle = New Rectangle(e.MarginBounds.Location,Me.DisplayRectangle.Size)
e.Graphics.Clip = New Region(e.MarginBounds)
Dim a As New Bitmap(r.Width, r.Height, e.Graphics)
Me.DrawToBitmap(a, r)
'Draw bitmap to printer graphics object
e.Graphics.DrawImage(a, r)
e.Graphics.ResetClip()
a = Nothing
'continue print other page or not
e.HasMorePages = False
End Sub
Then print function:
Private Sub Print()
'Seting Page Setup
PageSetupDialog1.PageSettings.Margins.Top = 0 PageSetupDialog1.PageSettings.Margins.Bottom = 0
PageSetupDialog1.PageSettings.Margins.Left = 0
PageSetupDialog1.PageSettings.Margins.Right = 0
Me.PrintPreviewDialog1.Document = Me.PrintDocument1
Me.PrintPreviewDialog1.ShowDialog()
Me.PrintPreviewDialog1.Document = pdOld
End Sub
Subscribe to:
Posts (Atom)
