The OnEndPage event and a table with a RowSpan - css

I added the creation of a table cone page header in OnEndPage. In table I a RowSpan that is not printed, while the rest is.
table.WriteSelectedRows (0, -1, pageSize.GetLeft (25), pageSize.GetTop (10), cb);
If I remove the RowSpan prints!

This is the code I use:
public override void OnEndPage(PdfWriter writer, Document document)
{
if (document.PageNumber != 1)
{
if (report.repeatHead) //ripete l'intestazione del report su tutte le pagine di stampa
{
repeatHead(writer, document);
}
else
{
if (document.PageNumber == 2) //ripete l'intestazione del report solo sulla second pagina dopo la copertina
{
repeatHead(writer, document);
}
}
}
}
public void repeatHead(PdfWriter writer, Document document)
{
//OnStartPage
base.OnStartPage(writer, document);
Rectangle pageSize = document.PageSize;
PdfPTable table = new PdfPTable(2);
//table.WidthPercentage = 100;
table.TotalWidth = pageSize.Width - 50;
table.DefaultCell.Border = Rectangle.NO_BORDER;
//impostazione larghezza celle
iTextSharp.text.Rectangle rect = PageSize.A4;
float pageWidth = rect.Width;
table.SetWidthPercentage(new float[]
{
(float).70 * pageWidth ,
(float).30 * pageWidth,
}, rect);
//Cella nome banca
table.AddCell(CellTest(report.banca, 1, 2));
//Cella descrizione indagine
table.AddCell(CellTest("Valore1", 0, 0));
//Cella data apertura
table.AddCell(CellTest("Data apertura: " + DateTime.Now, 0, 0));
//Cella descrizione
table.AddCell(CellTest("Descrizione", 0, 0));
//Cella data chiusura
table.AddCell(CellTest("Data chiusura: " + DateTime.Now, 0, 0));
table.WriteSelectedRows(0, -1, pageSize.GetLeft(25), pageSize.GetTop(10), cb);
}
private PdfPCell CellTest(string value, int colSpan, int rowSpan)
{
iTextSharp.text.Font font = FontFactory.GetFont("Arial");
PdfPCell c = new PdfPCell(new Phrase(value, font));
c.BorderWidthLeft = 1f;
c.BorderWidthTop = 1f;
c.BorderWidthRight = 1f;
c.BorderWidthBottom = 1f;
if (rowSpan != 0) { c.Rowspan = rowSpan; }
if (colSpan != 0) { c.Colspan = colSpan; }
return c;
}
public override void OnCloseDocument(PdfWriter writer, Document document)
{
base.OnCloseDocument(writer, document);
template.BeginText();
template.SetFontAndSize(bf, 8);
template.SetTextMatrix(0, 0);
template.ShowText("" + (writer.PageNumber - 1));
template.EndText();
}

Related

How to split or device an Entry into small entries in Xamarin forms

Hi Guys, I'm building an app that has an Entry similar to that of tinder, does anyone have an idea on how I can achieve this. I tried creating multiple entries and move focus on the text entered but deleting is the issue as TextChaned method is only called when there is text
In Xamarin.Forms , you can Custom a Entry Render View in iOS to implement it .
Create a custom Entry :
public class CustomEntry : Entry
{
}
Then in Native iOS, create a CustomEntryRenderer :
public class CustomEntryRenderer : EntryRenderer
{
private UITextField textField;
int numberCount = 6;
nfloat itemMargin =20;
List<UILabel> labels = new List<UILabel>();
List<UIView> lines = new List<UIView>();
UIControl maskView = new UIControl();
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
textField = (UITextField)this.Control;
//textField.ReturnKeyType = UIReturnKeyType.Done;
textField.KeyboardType = UIKeyboardType.NumberPad;
textField.AutocapitalizationType = UITextAutocapitalizationType.None;
textField.TextColor = UIColor.Clear;
textField.TintColor = UIColor.Clear;
textField.EditingChanged += TextField_EditingChanged;
UIButton maskView = new UIButton();
maskView.BackgroundColor = UIColor.White;
maskView.TouchUpInside += MaskView_TouchUpInside;
textField.AddSubview(maskView);
this.maskView = maskView;
for (int i = 0; i < numberCount; i++)
{
UILabel label = new UILabel();
label.TextAlignment = UITextAlignment.Center;
label.TextColor = UIColor.DarkTextColor;
label.Font = UIFont.FromName("PingFangSC-Regular", 41);
textField.AddSubview(label);
labels.Add(label);
}
for(int i = 0; i < numberCount; i++)
{
UIView line = new UIView();
line.BackgroundColor = UIColor.Purple;
textField.AddSubview(line);
lines.Add(line);
}
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
nfloat temp = textField.Bounds.Size.Width - (itemMargin * (numberCount - 1));
nfloat w = temp / numberCount;
nfloat x = 0;
for(int i = 0; i < labels.Count; i++)
{
x = i * (w + itemMargin);
UILabel label = labels[i];
label.Frame = new CGRect(x, 0, w, textField.Bounds.Size.Height);
UIView line = lines[i];
line.Frame = new CGRect(x, textField.Bounds.Size.Height - 1, w, 1);
}
maskView.Frame = textField.Bounds;
}
private void MaskView_TouchUpInside(object sender, EventArgs e)
{
textField.BecomeFirstResponder();
}
private void TextField_EditingChanged(object sender, EventArgs e)
{
if(textField.Text.Length > numberCount)
{
//Range range = new Range(0, numberCount);
textField.Text = textField.Text.Substring(0, numberCount);
}
for(int i = 0; i < numberCount; i++)
{
UILabel label = labels[i];
if(i< textField.Text.Length)
{
label.Text = textField.Text.Substring(i, 1);
}
else
{
label.Text = "";
}
}
if (textField.Text.Length >= numberCount)
{
textField.ResignFirstResponder();
}
}
}
Finally , you can use it in Xaml :
<ProjectNameSpace:CustomEntry x:Name="customEntry" WidthRequest="300" />
The effect :

JComboBox stops responding when focus is directed to another component

I'm having an issue with a small personal application I am puttig together. I am loading data into a JDialog. Within the JDialog, I am loading multiple JPanels that each contain a TableLayout. I am dynamically generating the rows from the data that is loaded into the JDialog. Each row contains a JComboBox and a JTextField that are use to make comments about the status of that particular set of data.
The problem I am encountering has to do with the JComboBox components that are being created. When the JDialog window opens, the JComboBox components are visable and working. Although, as soon as I direct the focus to a different type of component, the JComboBox components stop responding to the mouse clicks.
There is no special logic around the JComboBox components. They simply populate with four different string values, which the user should be able to choose from. No ChangeListener is required for this.
Also note, I wrap all the content in a ScrollPane within the JDialog.
The following is the code where I create the JComboBox components within the TableLayout of the JPanel:
private JPanel createColumnPanel() {
int columnCount = report.getColumns().size();
int rowCount = (columnCount * 2) - 1;
SpringLayout layout = new SpringLayout();
JPanel padding = new JPanel(layout);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Column Differences: ");
border.setTitleJustification(TitledBorder.LEFT);
double[] columns = new double[] {3, 75, 3, 175, 3, 150, 3, 100, 3, 125};
double[] rows = new double[rowCount];
for(int i = 0; i < rowCount; i++) {
rows[i] = 20;
if (i + 1 < rowCount)
rows[i + 1] = 5;
i++;
}
double size[][] = {columns, rows};
JPanel panel = new JPanel(new TableLayout(size));
columnStatus = new ArrayList<JComboBox<String>>();
for(int i = 0; i < columnCount; i++) {
JComboBox<String> comboBox = new JComboBox<String>(statusLiterals);
comboBox.setEnabled(true);
columnStatus.add(comboBox);
}
for (int i = 0; i < columnCount; i++) {
panel.add(new JLabel(report.getColumns().get(i).getSchema().toString()), 1 + ", " + (i * 2));
panel.add(new JLabel(report.getColumns().get(i).getTableName()), 3 + ", " + (i * 2));
panel.add(new JLabel(report.getColumns().get(i).getColumnName()), 5 + ", " + (i * 2));
panel.add(columnStatus.get(i), 7 + ", " + (i * 2));
panel.add(new JTextField(report.getColumns().get(i).getRequestor()), 9 + ", " + (i * 2));
}
panel.setBorder(border);
panel.setVisible(true);
panel.setAlignmentX(LEFT_ALIGNMENT);
panel.setBackground(Color.WHITE);
layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding);
layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel);
layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel);
layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding);
padding.add(panel, SwingConstants.CENTER);
padding.setBackground(Color.WHITE);
return padding;
}
The following is the full code for this particular JDialog:
public class ManageRequestsDialog extends JDialog {
private static final long serialVersionUID = 1L;
private ComparisonReport report;
private JPanel outerPanel;
private ScrollPane scrollPane;
private JPanel innerPanel;
private JPanel databasePanel;
private JPanel tablePanel;
private JPanel columnPanel;
private List<JLabel> databaseSchemas = null;
private List<JComboBox<String>> databaseStatus = null;
private List<JTextField> databaseRequestors = null;
private List<JLabel> tableSchemas = null;
private List<JLabel> tableTableNames = null;
private List<JComboBox<String>> tableStatus = null;
private List<JTextField> tableRequestors = null;
private List<JLabel> columnSchemas = null;
private List<JLabel> columnTableNames = null;
private List<JLabel> columnColumnNames = null;
private List<JComboBox<String>> columnStatus = null;
private List<JTextField> columnRequestors = null;
private String[] statusLiterals = DifferenceStatus.getLiterals();
public ManageRequestsDialog (ComparisonReport report) {
super();
this.report = report;
outerPanel = createOuterPanel();
add(outerPanel);
setLayout(new GridLayout(1, 1));
setModal(true);
setSize(700, 500);
setBackground(Color.WHITE);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
}
private JPanel createOuterPanel() {
JPanel panel = new JPanel(new GridLayout(1, 1));
scrollPane = createScrollPane();
panel.add(scrollPane);
panel.setVisible(true);
panel.setBackground(Color.WHITE);
return panel;
}
private ScrollPane createScrollPane() {
ScrollPane scrollPane = new ScrollPane();
innerPanel = createInnerPanel();
scrollPane.add(innerPanel);
scrollPane.setVisible(true);
scrollPane.setBackground(Color.WHITE);
return scrollPane;
}
private JPanel createInnerPanel() {
JPanel panel = new JPanel(new BorderLayout());
if (report.getDatabases().size() > 0) {
databasePanel = createDatabasePanel();
panel.add(databasePanel, BorderLayout.NORTH);
}
if (report.getTables().size() > 0) {
tablePanel = createTablePanel();
panel.add(tablePanel, BorderLayout.CENTER);
}
if (report.getColumns().size() > 0) {
columnPanel = createColumnPanel();
panel.add(columnPanel, BorderLayout.SOUTH);
}
panel.setVisible(true);
panel.setBackground(Color.WHITE);
return panel;
}
private JPanel createDatabasePanel() {
int databaseCount = report.getDatabases().size();
int rowCount = (databaseCount * 2) - 1;
SpringLayout layout = new SpringLayout();
JPanel padding = new JPanel(layout);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Database Differences: ");
border.setTitleJustification(TitledBorder.LEFT);
double[] columns = new double[] {3, 75, 3, 75, 3, 150};
double[] rows = new double[rowCount];
for(int i = 0; i < rowCount; i++) {
rows[i] = 20;
if (i + 1 < rowCount)
rows[i + 1] = 5;
i++;
}
double size[][] = {columns, rows};
JPanel panel = new JPanel(new TableLayout(size));
databaseStatus = new ArrayList<JComboBox<String>>();
for(int i = 0; i < databaseCount; i++) {
JComboBox<String> comboBox = new JComboBox<String>(statusLiterals);
comboBox.setEnabled(true);
databaseStatus.add(comboBox);
}
for (int i = 0; i < databaseCount; i++) {
panel.add(new JLabel(report.getDatabases().get(i).getSchema().toString()), 1 + ", " + (i * 2));
panel.add(databaseStatus.get(i), 3 + ", " + (i * 2));
panel.add(new JTextField(report.getDatabases().get(i).getRequestor()), 5 + ", " + (i * 2));
}
panel.setBorder(border);
panel.setVisible(true);
panel.setAlignmentX(LEFT_ALIGNMENT);
panel.setBackground(Color.WHITE);
layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding);
layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel);
layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel);
layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding);
padding.add(panel, SwingConstants.CENTER);
padding.setBackground(Color.WHITE);
return padding;
}
private JPanel createTablePanel() {
int tableCount = report.getTables().size();
int rowCount = (tableCount * 2) - 1;
SpringLayout layout = new SpringLayout();
JPanel padding = new JPanel(layout);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Table Differences: ");
border.setTitleJustification(TitledBorder.LEFT);
double[] columns = new double[] {3, 75, 3, 175, 3, 100, 3, 150};
double[] rows = new double[rowCount];
for(int i = 0; i < rowCount; i++) {
rows[i] = 20;
if (i + 1 < rowCount)
rows[i + 1] = 5;
i++;
}
double size[][] = {columns, rows};
JPanel panel = new JPanel(new TableLayout(size));
tableStatus = new ArrayList<JComboBox<String>>();
for(int i = 0; i < tableCount; i++) {
JComboBox<String> comboBox = new JComboBox<String>(statusLiterals);
comboBox.setEnabled(true);
tableStatus.add(comboBox);
}
for (int i = 0; i < tableCount; i++) {
panel.add(new JLabel(report.getTables().get(i).getSchema().toString()), 1 + ", " + (i * 2));
panel.add(new JLabel(report.getTables().get(i).getTableName()), 3 + ", " + (i * 2));
panel.add(tableStatus.get(i), 5 + ", " + (i * 2));
panel.add(new JTextField(report.getTables().get(i).getRequestor()), 7 + ", " + (i * 2));
}
panel.setBorder(border);
panel.setVisible(true);
panel.setAlignmentX(LEFT_ALIGNMENT);
panel.setBackground(Color.WHITE);
layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding);
layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel);
layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel);
layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding);
padding.add(panel, SwingConstants.CENTER);
padding.setBackground(Color.WHITE);
return padding;
}
private JPanel createColumnPanel() {
int columnCount = report.getColumns().size();
int rowCount = (columnCount * 2) - 1;
SpringLayout layout = new SpringLayout();
JPanel padding = new JPanel(layout);
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Column Differences: ");
border.setTitleJustification(TitledBorder.LEFT);
double[] columns = new double[] {3, 75, 3, 175, 3, 150, 3, 100, 3, 125};
double[] rows = new double[rowCount];
for(int i = 0; i < rowCount; i++) {
rows[i] = 20;
if (i + 1 < rowCount)
rows[i + 1] = 5;
i++;
}
double size[][] = {columns, rows};
JPanel panel = new JPanel(new TableLayout(size));
columnStatus = new ArrayList<JComboBox<String>>();
for(int i = 0; i < columnCount; i++) {
JComboBox<String> comboBox = new JComboBox<String>(statusLiterals);
comboBox.setEnabled(true);
columnStatus.add(comboBox);
}
for (int i = 0; i < columnCount; i++) {
panel.add(new JLabel(report.getColumns().get(i).getSchema().toString()), 1 + ", " + (i * 2));
panel.add(new JLabel(report.getColumns().get(i).getTableName()), 3 + ", " + (i * 2));
panel.add(new JLabel(report.getColumns().get(i).getColumnName()), 5 + ", " + (i * 2));
panel.add(columnStatus.get(i), 7 + ", " + (i * 2));
panel.add(new JTextField(report.getColumns().get(i).getRequestor()), 9 + ", " + (i * 2));
}
panel.setBorder(border);
panel.setVisible(true);
panel.setAlignmentX(LEFT_ALIGNMENT);
panel.setBackground(Color.WHITE);
layout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, padding);
layout.putConstraint(SpringLayout.SOUTH, padding, 10, SpringLayout.SOUTH, panel);
layout.putConstraint(SpringLayout.EAST, padding, 10, SpringLayout.EAST, panel);
layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, padding);
padding.add(panel, SwingConstants.CENTER);
padding.setBackground(Color.WHITE);
return padding;
}
}

OpenCL imaging - only one pixel is updated

I'm using Opencl.net and I'm trying to do some image processing on the GPU. Unfortunately only the first pixel ([0;0]) has the correct value, and the rest is (0;0;0;0). The OpenCL kernel should assign 0.5 to all color components of every pixel. It seems to me that the kernel is being executed only once (or perhaps the read function is reading only the first pixel). What am I doing wrong? I've omitted not relevant parts from my code:
...
int intPtrSize = 0;
intPtrSize = Marshal.SizeOf(typeof(IntPtr));
Cl.Mem srcImage2DBuffer;
Cl.ImageFormat imageFormat = new Cl.ImageFormat(Cl.ChannelOrder.ARGB, Cl.ChannelType.Float);
int imgWidth = 0, imgHeight = 0;
IntPtr srcFloatDataPtr;
int srcIMGBytesSize = 0;
GCHandle pinnedSrcFloatArray;
//Load image from file into OpenCL buffer
using (FileStream imageFileStream = new FileStream(inputImagePath, FileMode.Open) ) {
System.Drawing.Image inputImage = System.Drawing.Image.FromStream( imageFileStream );
imgWidth = inputImage.Width;
imgHeight = inputImage.Height;
System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(inputImage);
BitmapData bitmapData = bmpImage.LockBits( new Rectangle(0, 0, bmpImage.Width, bmpImage.Height),
ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
srcIMGBytesSize = bitmapData.Stride * bitmapData.Height;
//Convert image from byte to float array
byte[] inputByteArray = new byte[srcIMGBytesSize];
Marshal.Copy(bitmapData.Scan0, inputByteArray, 0, srcIMGBytesSize);
bmpImage.UnlockBits( bitmapData );
float[] inputFloatArray = new float[srcIMGBytesSize];
Array.Copy(inputByteArray, inputFloatArray, srcIMGBytesSize);
for (int i = 0; i < srcIMGBytesSize; i++) {
inputFloatArray[i] /= 255.0f;
}
pinnedSrcFloatArray = GCHandle.Alloc(inputFloatArray, GCHandleType.Pinned);
srcFloatDataPtr = pinnedSrcFloatArray.AddrOfPinnedObject();
srcImage2DBuffer = Cl.CreateImage2D(_context, Cl.MemFlags.CopyHostPtr | Cl.MemFlags.ReadOnly, imageFormat,
(IntPtr)bitmapData.Width, (IntPtr)bitmapData.Height,
(IntPtr)0, srcFloatDataPtr, out error);
}
float[] outputFloatArray = new float[srcIMGBytesSize];
//I'm not sure whether the pointer here is correct or not.
Cl.Mem resultImage2DBuffer = Cl.CreateImage2D(_context, Cl.MemFlags.CopyHostPtr | Cl.MemFlags.WriteOnly, imageFormat,
(IntPtr)imgWidth, (IntPtr)imgHeight, (IntPtr)0, outputFloatDataPtr, out error);
error = Cl.SetKernelArg(kernel, 0, (IntPtr)intPtrSize, srcImage2DBuffer);
error |= Cl.SetKernelArg(kernel, 1, (IntPtr)intPtrSize, resultImage2DBuffer);
...
IntPtr[] originPtr = new IntPtr[] { (IntPtr)0, (IntPtr)0, (IntPtr)0 };
IntPtr[] regionPtr = new IntPtr[] { (IntPtr)1, (IntPtr)1, (IntPtr)1 };
IntPtr[] workGroupSizePtr = new IntPtr[] { (IntPtr)imgWidth, (IntPtr)imgHeight, (IntPtr)1 };
error = Cl.EnqueueWriteImage(cmdQueue, srcImage2DBuffer, Cl.Bool.True, originPtr, regionPtr, (IntPtr)0, (IntPtr)0, srcFloatDataPtr, 0, null, out clevent);
pinnedSrcFloatArray.Free();
error = Cl.EnqueueNDRangeKernel(cmdQueue, kernel, 2, null, workGroupSizePtr, null, 0, null, out clevent);
error = Cl.EnqueueReadImage(cmdQueue, resultImage2DBuffer, Cl.Bool.True, originPtr, regionPtr,
(IntPtr)0, (IntPtr)0, outputFloatArray, 0, null, out clevent);
for (int i = 0; i < srcIMGBytesSize; i++) {
outputFloatArray[i] *= 255.0f;
}
//Right here I'm learning that all of the components are 0
for (int i = 0; i < srcIMGBytesSize; i+=4) {
Console.WriteLine("(" + outputFloatArray[i] + "; " + outputFloatArray[i+1] + "; "
+ outputFloatArray[i+2] + "; " + outputFloatArray[i+3] + ")");
}
Thank you!
I've figured out the problem. The region in Cl.EnqueueWriteImage/Cl.EnqueueReadImage should be (imageWidth, imageHeight, 1) instead of (1, 1, 1):
IntPtr[] regionPtr = new IntPtr[] { (IntPtr)imgWidth, (IntPtr)imgHeight, (IntPtr)1 };

Itextsharp: Is There Any Way To Copy Links When Import Pages?

I'm working on a project where i need to edit pdf's before display it
I need
add a watermark
edit permissions ( lock for avoid 'copy/paste' and 'save as' )
edit viewer preferences
And i did it... and work fine except for one thing, the links in the original file does not work in the new file... any idea?
NOTE: Actually, this is my code ( i'm using itextsharp )
private void loadPdf()
{
if (Request.QueryString.HasKeys())
{
if (Request.QueryString.GetKey(0) == "thepath" && Request.QueryString.GetKey(1) == "isprintable" && Request.QueryString.GetKey(2) == "type")
{
#region kuak
Document doc = new Document();
PdfReader pdfReader = new PdfReader(Request.QueryString["thepath"]);
using (MemoryStream memoryStream = new MemoryStream())
{
PdfWriter pdfWriter = PdfWriter.GetInstance(doc, memoryStream);
pdfWriter.ViewerPreferences = PdfWriter.PageModeUseOutlines;
//pdfWriter.ViewerPreferences = PdfWriter.PageLayoutTwoColumnLeft; /// Despliega el docuemnto en pares de hojas
pdfWriter.ViewerPreferences = PdfWriter.PageLayoutOneColumn;
pdfWriter.ViewerPreferences = PdfWriter.HideToolbar;
//pdfWriter.ViewerPreferences = PdfWriter.HideWindowUI; /// quita los scrollbars y el panel de la derecha qur contiene los bookmarks y las buskedas dentro del pdf
if (Request.QueryString["isprintable"] == "n")
{
pdfWriter.ViewerPreferences = PdfWriter.HideMenubar;
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
pdfWriter.SetEncryption(null, encoding.GetBytes("mYpAssss"), 0, PdfWriter.STRENGTH40BITS);
}
doc.Open();
PdfContentByte pdfContentByte = pdfWriter.DirectContent;
doc.AddDocListener(pdfWriter);
for (int page = 1; page <= pdfReader.NumberOfPages; page++)
{
//doc.SetPageSize(pdfReader.GetPageSize(page));
doc.SetPageSize(pdfReader.GetPageSizeWithRotation(page));
doc.NewPage();
PdfImportedPage pdfImportedPage = pdfWriter.GetImportedPage(pdfReader, page);
int rot = pdfReader.GetPageRotation(page);
if (rot == 90 || rot == 270)
pdfContentByte.AddTemplate(pdfImportedPage, 0, -1.0F, 1.0F, 0, 0, pdfReader.GetPageSizeWithRotation(page).Height);
else
pdfContentByte.AddTemplate(pdfImportedPage, 1.0F, 0, 0, 1.0F, 0, 0);
string theId = findId();
if (isWatermarkNeeded(theId))
{
#region ADD TEXT WATERMARK
//pdfContentByte.BeginText();
//iTextSharp.text.Rectangle pageSize = pdfReader.GetPageSizeWithRotation(page);
//BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, System.Text.Encoding.ASCII.EncodingName, false);
//pdfContentByte.SetFontAndSize(baseFont, 200);
//BaseColor baseColor = new BaseColor(255, 0, 0, 20);
//pdfContentByte.SetColorFill(baseColor);
//float textAngle = (float)GetHypotenuseAngleInDegreesFrom(pageSize.Height, pageSize.Width);
//pdfContentByte.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "DRAFT", 350, pageSize.Height / 2, textAngle);
//pdfContentByte.EndText();
#endregion
#region ADD IMAGE WATERMARK
string fechaExp = "Este documento vence: " + GetExpirationDate(theId).ToShortDateString();
pdfContentByte.BeginText();
//iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/watermark3.png"));
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ImageCheck.CreatePicture(#"C:\Users\myUser\Desktop\watermark.png", fechaExp).ToArray());
img.SetAbsolutePosition(0, 0);
pdfContentByte.AddImage(img);
pdfContentByte.EndText();
#endregion
}
}
pdfReader.Close();
doc.Close();
byte[] content = memoryStream.ToArray();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", content.Length.ToString());
Response.BinaryWrite(content);
}
#endregion
}
else
{
//hay querystring pro no corresponden con los que se necesita
}
}
else
{
//no se enviaron los querystring
}
}
You have to get the links from original PDF
var links = reader.GetLinks(pageNumber);
And write them to the new PDF
foreach (var link in links)
{
var annotation = link.CreateAnnotation(pdfWriter);
writer.AddAnnotation(annotation);
}

datatype image in $.ajax

in page cap.aspx
==========================================================================
string code = GetRandomText();
Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.LavenderBlush);
Rectangle rect = new Rectangle(0,0,160,50);
SolidBrush b = new SolidBrush(Color.LightPink);
SolidBrush blue = new SolidBrush(Color.White);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
bitmap.Save(Response.OutputStream,ImageFormat.Gif);
g.Dispose();
b.Dispose();
blue.Dispose();
bitmap.Dispose();
===================================================================================
<div id="DIVdialog" style="display:none">
<img src="cap.aspx"/>
</div>
===================================================================================
$("#DIVdialog").dialog();
==================================================================================
show dialog but does not show image? address cap.aspx is correct!
how get cap.aspx by $.ajax and datatype:image?
I think that the key here is to add the ContentType and the BufferOutput
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
Eg:
public void RenderIt(HttpContext context)
{
context.Response.ContentType = "image/gif";
context.Response.BufferOutput = false;
string code = GetRandomText();
using(Bitmap bitmap = new Bitmap(160,50,System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using(Graphics g = Graphics.FromImage(bitmap))
{
using(Pen pen = new Pen(Color.LavenderBlush)
{
using(SolidBrush b = new SolidBrush(Color.LightPink))
{
using(SolidBrush blue = new SolidBrush(Color.White))
{
Rectangle rect = new Rectangle(0,0,160,50);
int counter = 0;
g.DrawRectangle(pen, rect);
g.FillRectangle(b, rect);
for (int i = 0; i < code.Length; i++)
{
g.DrawString(code[i].ToString(), new Font("Tahoma", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
counter += 20;
}
DrawRandomLines(g);
g.Dispose();
b.Dispose();
blue.Dispose();
// Return
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
// Dispose
bitmap.Dispose();
}
}
}
}
}
context.Response.End();
}

Resources