Print a header on set page using Abc PDF - pdf-generation

I have created pdf from HTML page using Abc PDF now my problem is I want to print a table header on next page, but only if table data is display within a another page, if not display header on a different page, any one have idea about how we can do this using Abc pdf.

What you need to do is create the page with some space at the top, then once your document is built in abc PDF loop though the pages and add a header.
The code below is what I use to add a header, the header in this case has three bits a image at the top and two boxes with text in.
Remember the cord in abc pdf are from the bottom right not the top left.
private static Doc AddHeader(Doc theDoc, Core.Property propertyDetails)
{
int theCount = theDoc.PageCount;
int i = 0;
//Image header
for (i = 1; i <= theCount; i++)
{
theDoc.Rect.Width = 590;
theDoc.Rect.Height = 140;
theDoc.Rect.Position(0, 712);
theDoc.PageNumber = i;
//Check Which office to use.
string imagefilePath = HttpContext.Current.Server.MapPath("/images/pdf/pdf-header.png");
Bitmap myBmp = (Bitmap)Bitmap.FromFile(imagefilePath);
theDoc.AddImage(myBmp);
}
//page header boxes.
//Grey header box
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 672);
System.Drawing.Color colour = System.Drawing.ColorTranslator.FromHtml("#CCCCCC");
theDoc.Color.Color = colour;
theDoc.PageNumber = 1;
theDoc.FillRect();
theDoc.Rect.String = "20 15 586 50";
theDoc.Rect.Position(30, 660);
System.Drawing.Color pageoneText = System.Drawing.ColorTranslator.FromHtml("#50474A");
theDoc.Color.Color = pageoneText;
string thePageFont = "Century Gothic";
theDoc.Font = theDoc.AddFont(thePageFont);
theDoc.FontSize = 16;
theDoc.PageNumber = 1;
theDoc.AddText("My Text!!!!!");
theDoc.Rect.String = "20 15 590 50";
theDoc.Rect.Position(13, 630);
System.Drawing.Color greyBox = System.Drawing.ColorTranslator.FromHtml("#468DCB");
theDoc.Color.Color = greyBox;
theDoc.PageNumber = 1;
theDoc.FillRect();
theDoc.Rect.String = "20 15 586 50";
theDoc.Rect.Position(30, 620);
System.Drawing.Color greyText = System.Drawing.ColorTranslator.FromHtml("#ffffff");
theDoc.Color.Color = greyText;
string thePageFontTwo = "Century Gothic";
theDoc.Font = theDoc.AddFont(thePageFontTwo);
theDoc.FontSize = 14;
theDoc.PageNumber = 1;
theDoc.AddText("This is more text");
return theDoc;
}
Then once the pdf file is created just call
var theDoc = new Doc();
/// Your document creation stuff!!!
theDoc = AddHeader(theDoc, propertyDetails);

Related

InDesign Text Modification Script Skips Content

This InDesign Javascript iterates over textStyleRanges and converts text with a few specific appliedFont's and later assigns a new appliedFont:-
var textStyleRanges = [];
for (var j = app.activeDocument.stories.length-1; j >= 0 ; j--)
for (var k = app.activeDocument.stories.item(j).textStyleRanges.length-1; k >= 0; k--)
textStyleRanges.push(app.activeDocument.stories.item(j).textStyleRanges.item(k));
for (var i = textStyleRanges.length-1; i >= 0; i--) {
var myText = textStyleRanges[i];
var converted = C2Unic(myText.contents, myText.appliedFont.fontFamily);
if (myText.contents != converted)
myText.contents = converted;
if (myText.appliedFont.fontFamily == 'Chanakya'
|| myText.appliedFont.fontFamily == 'DevLys 010'
|| myText.appliedFont.fontFamily == 'Walkman-Chanakya-905') {
myText.appliedFont = app.fonts.item("Utsaah");
myText.composer="Adobe World-Ready Paragraph Composer";
}
}
But there are always some ranges where this doesn't happen. I tried iterating in the forward direction OR in the backward direction OR putting the elements in an array before conversion OR updating the appliedFont in the same iteration OR updating it a different one. Some ranges are still not converted completely.
I am doing this to convert the Devanagari text encoded in glyph based non-Unicode encoding to Unicode. Some of this involves repositioning vowel signs etc and changing the code to work with find/replace mechanism may be possible but is a lot of rework.
What is happening?
See also: http://cssdk.s3-website-us-east-1.amazonaws.com/sdk/1.0/docs/WebHelp/app_notes/indesign_text_frames.htm#Finding_and_changing_text
Sample here: https://www.dropbox.com/sh/7y10i6cyx5m5k3c/AAB74PXtavO5_0dD4_6sNn8ka?dl=0
This is untested since I'm not able to test against your document, but try using getElements() like below:
var doc = app.activeDocument;
var stories = doc.stories;
var textStyleRanges = stories.everyItem().textStyleRanges.everyItem().getElements();
for (var i = textStyleRanges.length-1; i >= 0; i--) {
var myText = textStyleRanges[i];
var converted = C2Unic(myText.contents, myText.appliedFont.fontFamily);
if (myText.contents != converted)
myText.contents = converted;
if (myText.appliedFont.fontFamily == 'Chanakya'
|| myText.appliedFont.fontFamily == 'DevLys 010'
|| myText.appliedFont.fontFamily == 'Walkman-Chanakya-905') {
myText.appliedFont = app.fonts.item("Utsaah");
myText.composer="Adobe World-Ready Paragraph Composer";
}
}
A valid approach is to use hyperlink text sources as they stick to the genuine text object. Then you can edit those source texts even if they were actually moved elsewhere in the flow.
//Main routine
var main = function() {
//VARS
var doc = app.properties.activeDocument,
fgp = app.findGrepPreferences.properties,
cgp = app.changeGrepPreferences.properties,
fcgo = app.findChangeGrepOptions.properties,
text, str,
found = [], srcs = [], n = 0;
//Exit if no documents
if ( !doc ) return;
app.findChangeGrepOptions = app.findGrepPreferences = app.changeGrepPreferences = null;
//Settings props
app.findChangeGrepOptions.properties = {
includeHiddenLayers:true,
includeLockedLayersForFind:true,
includeLockedStoriesForFind:true,
includeMasterPages:true,
}
app.findGrepPreferences.properties = {
findWhat:"\\w",
}
//Finding text instances
found = doc.findGrep();
n = found.length;
//Looping through instances and adding hyperlink text sources
//That's all we do at this stage
while ( n-- ) {
srcs.push ( doc.hyperlinkTextSources.add(found[n] ) );
}
//Then we edit the stored hyperlinks text sources 's texts objects contents
n = srcs.length;
while ( n-- ) {
text = srcs[n].sourceText;
str = text.contents;
text.contents = str+str+str+str;
}
//Eventually we remove the added hyperlinks text sources
n = srcs.length;
while ( n-- ) srcs[n].remove();
//And reset initial properties
app.findGrepPreferences.properties = fgp;
app.changeGrepPreferences.properties = cgp;
app.findChangeGrepOptions.properties =fcgo;
}
//Running script in a easily cancelable mode
var u;
app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

Adding delay in Processing

so I am new to Processing and basically I am doing a program that when it runs, it opens a window with 4 different images, each of the image have description underneath. In the methods below, I created two random methods, one for the reviews number and the other for the review comments, I would like the comments to not be generated all the time for every film - more like popping up randomly, because it cause too much chaos trying to read them all. Also to check weather I can add arrays together of string and integer for the average value of the review number.
Below is the code, would appreciate your help. thanks.
import g4p_controls.*;
import ddf.minim.*;
PFont font;
PImage img1,img2; // background images for two different windows
PImage fimg1, fimg2, fimg3, fimg4, fimg5, fimg6; //images of movies
int rectX,rectY;
GButton btn;
GWindow window;
Minim minim;
AudioPlayer player;
String[] rev_film1 = {"The Best Wolverine Movie","Logan is another level","Disappointment","Such a sad farewell"}; //Logan
String[] rev_film2 = {"A scary movie that isn't scary.","Terrifyingly brilliant.","The perfect blend of comedy and horror","The IT Factor"}; //IT
String[] rev_film3 = {"Soul-less,Confused,Loud.","Devastatingly Disappointed","A technical masterpiece","A visual wonder that lacks depth"}; //Dunkirk
String[] rev_film4 = {"Disgrace", "Worst Star Wars movie", "TERRIBLE","A Betrayal to the Legacy"}; //Starwars
int[] rat_film1 = {9,8,2,2};
float r;
void setup()
{
size(1150,600,JAVA2D);
surface.setTitle(" - The Theatre of Dreams Database - ");
font = loadFont("BerlinSansFB-Reg-48.vlw");
img1 = loadImage("film2.jpg");
background(img1);
btn = new GButton(this,900,350,100,50, "Enter Website");
minim = new Minim(this);
player = minim.loadFile("sound.mp3");
player.play();
}
void draw()
{
fill(255);
textFont(font,32);
text("Welcome to", 850, 85);
text("The Theatre of Dreams", 760, 175);
text("Database", 870, 220);
}
void handleButtonEvents(GButton button, GEvent event)
{
if (button == btn && event == GEvent.CLICKED)
{
createWindow();
btn.setEnabled(false);
}
}
void createWindow() // creating new window with mouse click
{
window = GWindow.getWindow(this, " - Top 4 Movies in 2017 - ", 100, 50, 1150, 600, JAVA2D);
window.addDrawHandler(this, "windowDraw");
window.addOnCloseHandler(this, "windowClosing");
window.setActionOnClose(GWindow.CLOSE_WINDOW);
}
void windowDraw(PApplet app, GWinData data)
{
img2 = loadImage("film3.jpg");
app.background(img2);
app.text(" - Top 4 Movies in 2017 - ",440,85);
app.fill(255);
app.textFont(font,25);
fimg1 = loadImage("logan.jpg");
fimg2 = loadImage("it.jpg");
fimg3 = loadImage("dunkirk.jpg");
fimg4 = loadImage("starwars.jpg");
//////////Film 1 - LOGAN
app.image(fimg1,5,140,180,170);
app.text("Rating: 8.1 / 10",5,340); //fixed rating
app.text("Genres: Action | Drama", 5, 365);
app.text("| Sci-Fi | Thriller",5,390);
//Ratings that are constantly changing using the random function
for (int i = 0; i < 50; i++)
{
r = random(0, 6);
}
String user = "Ratings by users: " + nf(r,0,1) + " / 10";
app.text(user, 5,430);
// the random function of the comments
int index = int(random(rev_film1.length));
String user11 = "Reviews: " + "\n" + rev_film1[index];
app.text(user11, 5,460);
////////////////////Film 2 - IT
app.image(fimg2,960,360,180,170);
app.text("Rating: 7.6 / 10", 700,400);
app.text("Genres: Drama | Horror",700,430);
app.text("| Thriller",700,460);
//Ratings that are constantly changing using the random function
for (int i = 0; i < 50; i++)
{
r = random(5, 10);
}
String user2 = "Ratings by users: " + nf(r,0,1) + " / 10";
app.text(user2, 700,500);
int index2 = int(random(rev_film2.length)); // the random function of the comments
String user22 = "Reviews: " + "\n" + rev_film2[index2];
app.text(user22, 700,540);
/////////Film 3 - DUNKIRK
app.image(fimg3,320,250,180,170);
app.text("Rating: 8.1 / 10",320,445); //fixed rating
app.text("Genres: Action | Drama", 320, 470);
app.text("| History | Thriller | War",320,495);
//Ratings that are constantly changing using the random function
for (int i = 0; i < 50; i++)
{
r = random(0, 5);
}
String user3 = "Ratings by users: " + nf(r,0,1) + " / 10";
app.text(user3, 320,530);
int index3 = int(random(rev_film3.length)); // the random function of the comments
String user33 = "Reviews: " + "\n" + rev_film3[index3];
app.text(user33, 320,560);
/////////////Film 4 - STAR WARS
app.image(fimg4,570,120,180,170);
app.text("Rating: 7.6 / 10", 760,140); //fixed rating
app.text("Genres: Action | Adventure | Fantasy ", 760,168);
app.text("| Sci-Fi", 760,195);
//Ratings that are constantly changing using the random function
for (int i = 0; i < 50; i++)
{
r = random(0, 2);
}
String user4 = "Ratings by users: " + nf(r,0,1) + " / 10";
app.text(user4, 760,220);
int index4 = int(random(rev_film4.length)); // the random function of the comments
String user44 = "Reviews: " + "\n" + rev_film4[index4];
app.text(user44, 760,250);
}
public void windowClosing(GWindow w)
{
btn.setEnabled(false);
player.close();
minim.stop();
exit();
}
Please try to post a MCVE instead of your full program. For example, try creating a simple sketch that shows a circle every X seconds. That way we can focus on your problem instead of all the extra stuff that has nothing to do with your question.
But to answer your question, you can use the millis() function or the frameCount variable to check how much time has gone by, then do something every X seconds or every X frames.
Related posts:
How to make a delay in processing project?
How can I draw only every x frames?
Removing element from ArrayList every 500 frames
Timing based events in Processing
How to add +1 to variable every 10 seconds in Processing?
How to create something happen when time = x
making a “poke back” program in processing
Processing: How do i create an object every “x” time
Timer using frameRate and frame counter reliable?
Please also consult the Processing reference for more information.
If you still can't get it working, please post a MCVE (not your full project!) in a new question and we'll go from there. Good luck.

Vulkan copying image from swap chain

I am using the vkCmdCopyImageToBuffer function and getting a memory access violation and don't understand why.
Here is the code:
VkBufferImageCopy region = {};
region.bufferOffset = 0;
region.bufferRowLength = width;
region.bufferImageHeight = height;
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageOffset = { 0, 0, 0 };
region.imageExtent = {
width,
height,
1
};
vkCmdCopyImageToBuffer(m_drawCmdBuffers[i], m_swapChain.buffers[i].image,
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_renderImage, 1, &region);
The swapchain images are created here in the initialization code:
// Get the swap chain images
images.resize(imageCount);
VK_CHECK_RESULT(fpGetSwapchainImagesKHR(device, swapChain, &imageCount, images.data()));
// Get the swap chain buffers containing the image and imageview
buffers.resize(imageCount);
for (uint32_t i = 0; i < imageCount; i++)
{
VkImageViewCreateInfo colorAttachmentView = {};
colorAttachmentView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
colorAttachmentView.pNext = NULL;
colorAttachmentView.format = colorFormat;
colorAttachmentView.components = {
VK_COMPONENT_SWIZZLE_R,
VK_COMPONENT_SWIZZLE_G,
VK_COMPONENT_SWIZZLE_B,
VK_COMPONENT_SWIZZLE_A
};
colorAttachmentView.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
colorAttachmentView.subresourceRange.baseMipLevel = 0;
colorAttachmentView.subresourceRange.levelCount = 1;
colorAttachmentView.subresourceRange.baseArrayLayer = 0;
colorAttachmentView.subresourceRange.layerCount = 1;
colorAttachmentView.viewType = VK_IMAGE_VIEW_TYPE_2D;
colorAttachmentView.flags = 0;
buffers[i].image = images[i];
colorAttachmentView.image = buffers[i].image;
VK_CHECK_RESULT(vkCreateImageView(device, &colorAttachmentView, nullptr, &buffers[i].view));
}
And my buffer is similarly created here:
VkBufferCreateInfo createinfo = {};
createinfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
createinfo.size = width * height * 4 * sizeof(int8_t);
createinfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
createinfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
//create the image copy buffer
vkCreateBuffer(m_device, &createinfo, NULL, &m_renderImage);
I have tried different pixel formats and different createinfo.usage settings but none help.
VkSurfaceCapabilitiesKHR::supportedUsageFlags defines the limitations on the ways in which you can use the VkImages created by the swap chain. The only one that is guaranteed to be supported is color attachment; all of the other, including transfer src, are optional.
Therefore, you should not assume that you can copy from a presentable image. If you find yourself with a need to do that, you must first query that value. If it does not allow copies, then you must render to your own image, which you copy from. You can render from that image into the presentable one when you intend to present it.

a bar to indicator the percentage, but not a progress bar

I need a bar which indicate a percentage of something, like battery engry or used space size of a hard disk. Like
This is not a progress bar. When I use progress bar, each time I send the message PBM_SETPOS, it will increase from 0 to the pos.
The bar must have the ability for me to set a value manually, and after it, it will change the color region to the specified length directly, rather than in a increasement way.
Does WinAPI has a build in function for this purpose?
Use a Panel and then set a label with in it...Then set the width of label with backcolor based on percentage...
Code as follows:
string s27 = "select percentage from CandidateReg3 where candidateid='" + candidateid + "'";
DataTable d17 = cn.viewdatatable(s27);
if (d17.Rows.Count > 0) {
for (int m = 0; m < d17.Rows.Count; m++) {
percreg3 = int.Parse(d17.Rows[m]["percentage"].ToString());
percregtotal = percreg3 + percreg;
}
} else {
percregtotal = percreg;
}
decimal percregtotals = (decimal)percregtotal / 100;
double percent = Convert.ToDouble(percregtotals);
// double percent = 1;
IndicatorLabel.Width = new Unit(percent * IndicatorPanel.Width.Value, UnitType.Pixel);
IndicatorLabel.ToolTip = percent.ToString("p0");
IndicatorLabel.Text = percent.ToString("p0");
IndicatorLabel.ForeColor=Color.White;
// IndicatorLabel.Text = "";
IndicatorLabel.BackColor = Color.Green;

Exporting ListView content to Excel?

I've been trying to export the content data of my ListView control into an Excel application using C#. I've already done this before using VB.NET and I tried to convert my code to C# but it failed but I made a modification on it and seems everything is fine on code below except for the last part which to save the data as an excel file. I need an assistance to modify this code correctly. I would greatly appreciate your helpful response.
The code below that got an error is:
oBook.SaveAs(SaveFileDialog1.InitialDirectory.ToString() + SaveFileDialog1.FileName);
Error 5 No overload for method 'SaveAs' takes '1' arguments
private void Button4_Click(object sender, System.EventArgs e)
{
int row = 0;
int col = 0;
int row2 = 0;
int col2 = 0;
int ch = 0;
int ctr = 0;
ctr = 0;
row2 = 1;
col2 = 3;
row = 3;
col = 3;
Microsoft.Office.Interop.Excel.Application oExcel = new Microsoft.Office.Interop.Excel.Application();
oExcel.Visible = false;
Microsoft.Office.Interop.Excel.Workbook oBook = oExcel.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);
Microsoft.Office.Interop.Excel.Worksheet oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oExcel.ActiveSheet;
SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
SaveFileDialog1.Filter = "Excel File|*.xlsx|Word File|*.doc|Text File|*.txt";
SaveFileDialog1.Title = "Save As";
if (SaveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
switch (SaveFileDialog1.FilterIndex)
{
case 1:
{
for (ch = 1; ch <= ListView1.Columns.Count; ch++)
{
oSheet.Cells[row2, col2] = ListView1.Columns[ctr].Text;
col2 = col2 + 1;
ctr = ctr + 1;
}
foreach (ListViewItem lview in ListView1.Items)
{
foreach (ListViewItem.ListViewSubItem lview2 in lview.SubItems)
{
oSheet.Cells[row, col] = lview2.Text;
col = col + 1;
}
col = 3;
row = row + 1;
}
oBook.SaveAs(SaveFileDialog1.InitialDirectory.ToString() + SaveFileDialog1.FileName);
oExcel.Quit();
SaveFileDialog1.Dispose();
MessageBox.Show("Data has been successfully saved", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
break;
}
}
The workbook SaveAs method takes 11 parameters. In C# you have to pass something for these optional parameters even if you do not care about them. The easiest thing to do here is pass System.Reflection.Missing.Value for those you do not care about. It is a pain though.

Resources