I am creating a PDF from scratch. We get lines of report data back from a UNIX system and then build a PDF version of the report that is to be a mirror of the UNIX generated report, but in PDF format on Windows. Below is the module that takes the reports lines and builds the PDF and then saves it to disk.
Code: Select all
#region . LoadPdfPage .
private void LoadPdfPage(string filename, string publishedfile)
{
//start GdPicture image object
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
oGdPictureImaging.SetLicenseNumberUpgrade(Statics.GdPictureLicense(), "XXX");
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
string FontCourierStd = string.Empty;
string FontCourierStdBold = string.Empty;
oGdPicturePDF.NewPDF(false);
oGdPicturePDF.SetAuthor("TraxView TraxReports");
oGdPicturePDF.SetTitle(_agtraxprogram + " - " + filename);
oGdPicturePDF.SetProducer("AgTrax Technologies");
oGdPicturePDF.SetSubject(_agtraxprogram + " - " + filename);
oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
if (parentControl != null)
{
parentControl.filescreated.Add(publishedfile);
}
if (parentForm != null)
{
parentForm.filescreated.Add(publishedfile);
}
FontCourierStd = oGdPicturePDF.AddStandardFont(PdfStandardFont.Courier);
FontCourierStdBold = oGdPicturePDF.AddStandardFont(PdfStandardFont.CourierBold);
oGdPicturePDF.NewPage(8.5F, 11F);
oGdPicturePDF.SetTextMode(PdfTextMode.PdfTextModeFill);
float currentline = 64;
string currentFont = string.Empty;
if (_fontsize == 7)
{
currentFont = FontCourierStd;
oGdPicturePDF.SetTextSize(7F);
}
else
{
currentFont = FontCourierStd;
oGdPicturePDF.SetTextSize(12F);
}
oGdPicturePDF.SetTextMode(PdfTextMode.PdfTextModeFill);
foreach (TraxView.AgTrax.Trrpt rptline in reportlines)
{
float currentlinepos = currentline / 6;
int linelength = rptline.Trfline.Length;
switch (rptline.Trftype)
{
case 1:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 3:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 5:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 6:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 7:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 16:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
case 18:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
default:
oGdPicturePDF.SetFillColor(0, 0, 0);
oGdPicturePDF.DrawText(currentFont, .12F, currentlinepos, rptline.Trfline);
break;
}
currentline = currentline - 1;
}
oGdPicturePDF.SaveToFile(publishedfile);
oGdPicturePDF.CloseDocument();
gdViewer.CloseDocument();
gdViewer.ZoomMode = GdPicture.ViewerZoomMode.ZoomModeWidthViewer;
gdViewer.DocumentAlignment = ViewerDocumentAlignment.DocumentAlignmentTopCenter;
gdViewer.DisplayFromFile(publishedfile);
}
#endregion . LoadPdfPage .
At this point we are very basic.
Thanks,
Bob