PdfContentByte cb = stamper.GetUnderContent(1);
PdfLayer layer = new PdfLayer("one", stamper.Writer);
Barcode39 barcodeParcel = new Barcode39();
barcodeParcel.Code = "TESTVALUE";
barcodeParcel.StartStopText = false;
Image imageBarcodeParcel = barcodeParcel.CreateImageWithBarcode(cb,
null, null);
stamper.Writer.Add(new Phrase(new Chunk(imageBarcodeParcel, 225,
333)));
stamper.Writer.Add(new Phrase(new Chunk(imageBarcodeParcel, 225,
157)));
Have any of you got this to work? If so, I'd appreciate any samples.
Thanks,
-Gary
/**
Adds a barcode to <code>cb</code>
*/
private void addBarcode(PdfContentByte cb, String symbology, String
value, float x1, float y1, float x2, float y2)
{
float h = y2-y1;
float w = x2-x1;
try
{
if(symbology.equalsIgnoreCase("postnet")) {
BarcodePostnet postNetBCD = new BarcodePostnet();
postNetBCD.setCode(value);
Image imagePostnet = postNetBCD.createImageWithBarcode(cb, null,
null);
imagePostnet.setAbsolutePosition(x1, y1);
cb.addImage(imagePostnet);
}
else if(symbology.equalsIgnoreCase("code128")) {
Barcode128 code128BCD = new Barcode128();
code128BCD.setCode(value);
code128BCD.setFont(null);
code128BCD.setBarHeight((int)h);
Image imageCode128 = code128BCD.createImageWithBarcode(cb, null,
null);
imageCode128.setAbsolutePosition(x1, y1);
cb.addImage(imageCode128);
}
else if(symbology.equalsIgnoreCase("code39")) {
Barcode39 code39BCD = new Barcode39();
code39BCD.setCode(value);
code39BCD.setFont(null);
code39BCD.setBarHeight((int)h);
Image imageCode39 = code39BCD.createImageWithBarcode(cb, null,
null);
imageCode39.setAbsolutePosition(x1, y1);
cb.addImage(imageCode39);
}
else if(symbology.equalsIgnoreCase("pdf417")) {
BarcodePDF417 pdf417BCD = new BarcodePDF417();
pdf417BCD.setText(value);
Image imagePDF417 = pdf417BCD.getImage();
imagePDF417.scaleAbsolute(w, h);
imagePDF417.setAbsolutePosition(x1, y1);
cb.addImage(imagePDF417);
}
}
catch (Exception e)
{
System.err.println(e.toString());
}
}
Thanks for the help! The following C# code --based off of the Java
provided-- is working...
PdfContentByte cb = stamper.GetUnderContent(1);
Barcode39 code39BCD = new Barcode39();
code39BCD.Code = parcel;
code39BCD.Font = null;
code39BCD.BarHeight = 16;
Image imageCode39 = code39BCD.CreateImageWithBarcode(cb, null, null);
imageCode39.SetAbsolutePosition(225, 342);
cb.AddImage(imageCode39);
BTW, The files are split across multiple directories containing 2500
pdfs a piece. I had planned to use your utility, pdftk, to merge the
output pdfs into a single document via a batch script. I'd like to
save a step and join all the files in a directory directly from the
script. If the code isn't too long, could you post pdftk's code
responsible for concatenating multiple files? (For example, "pdftk
*.pdf cat output combined.pdf").
Thanks,
-Gary
pdftk isn't my utility, it belongs to Sid Steward. I merely added my
own hack to it.
You can find the complete original source code here:
(Chicks didn't write pdftk; he extended it. Sid Steward wrote the
original pdftk.)
Off-the-cuff VB.NET code for concatenating:
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Function ConcatPDF(byref input() as string, output as string)
Dim doc As New Document(PageSize.LETTER)
Dim writer As New PdfCopy(doc, New IO.FileStream(filename,
IO.FileMode.CreateNew))
doc.Open()
For Each f As String In input
Dim rdr As New PdfReader(f)
For i As Integer = 1 To rdr.NumberOfPages
Dim pg As PdfImportedPage =
writer.GetImportedPage(rdr, i)
writer.AddPage(pg)
Next
Next
doc.Close()
End Function
This is a bit old fashioned, because I use PdfWriter and PdfReader
directly. It is possible that the somewhat newer PdfCopy class would
be better.
Thanks for all the responses.
FYI; I ended up directly calling pdftk with the following code:
private void CombineBills(int boxNumber)
{
Console.WriteLine(String.Format("Combining bills to{0}.",
String.Format(pdftkOptions, outputRoot, boxNumber,
boxNumber, outputRoot, boxNumber)));
ProcessStartInfo processInf = new ProcessStartInfo();
processInf.FileName = pdftkPath;
processInf.Arguments = String.Format(pdftkOptions,
outputRoot, boxNumber, boxNumber, outputRoot, boxNumber);
processInf.CreateNoWindow = true;
processInf.ErrorDialog = false;
processInf.UseShellExecute = true;
Process.Start(processInf);
}